summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-01-18 14:17:35 -0500
committerGitHub <noreply@github.com>2022-01-18 12:17:35 -0700
commitbcb7a19cd3fbc680a017bc2f5aafa71ff77e87e3 (patch)
tree52af9209510cafc0fff34ff376c4c05b1712d913 /modules/caddyhttp
parent6e6ce2be6be004f592978d9f020f0185b40af1a7 (diff)
rewrite: Add `method` Caddyfile directive (#4528)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/rewrite/caddyfile.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/caddyhttp/rewrite/caddyfile.go b/modules/caddyhttp/rewrite/caddyfile.go
index 9621af1..15abbfa 100644
--- a/modules/caddyhttp/rewrite/caddyfile.go
+++ b/modules/caddyhttp/rewrite/caddyfile.go
@@ -27,6 +27,7 @@ import (
func init() {
httpcaddyfile.RegisterHandlerDirective("rewrite", parseCaddyfileRewrite)
+ httpcaddyfile.RegisterHandlerDirective("method", parseCaddyfileMethod)
httpcaddyfile.RegisterHandlerDirective("uri", parseCaddyfileURI)
httpcaddyfile.RegisterDirective("handle_path", parseCaddyfileHandlePath)
}
@@ -51,6 +52,24 @@ func parseCaddyfileRewrite(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler,
return rewr, nil
}
+// parseCaddyfileMethod sets up a basic method rewrite handler from Caddyfile tokens. Syntax:
+//
+// method [<matcher>] <method>
+//
+func parseCaddyfileMethod(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
+ var rewr Rewrite
+ for h.Next() {
+ if !h.NextArg() {
+ return nil, h.ArgErr()
+ }
+ rewr.Method = h.Val()
+ if h.NextArg() {
+ return nil, h.ArgErr()
+ }
+ }
+ return rewr, nil
+}
+
// parseCaddyfileURI sets up a handler for manipulating (but not "rewriting") the
// URI from Caddyfile tokens. Syntax:
//