Francis Lavoie
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
48 additions and
1 deletions
-
caddyconfig/httpcaddyfile/directives.go
-
caddytest/integration/caddyfile_adapt/method_directive.txt
-
modules/caddyhttp/rewrite/caddyfile.go
|
@ -45,7 +45,8 @@ var directiveOrder = []string{ |
|
|
|
|
|
|
|
|
"redir", |
|
|
"redir", |
|
|
|
|
|
|
|
|
// URI manipulation
|
|
|
// incoming request manipulation
|
|
|
|
|
|
"method", |
|
|
"rewrite", |
|
|
"rewrite", |
|
|
"uri", |
|
|
"uri", |
|
|
"try_files", |
|
|
"try_files", |
|
|
|
@ -0,0 +1,27 @@ |
|
|
|
|
|
:8080 { |
|
|
|
|
|
method FOO |
|
|
|
|
|
} |
|
|
|
|
|
---------- |
|
|
|
|
|
{ |
|
|
|
|
|
"apps": { |
|
|
|
|
|
"http": { |
|
|
|
|
|
"servers": { |
|
|
|
|
|
"srv0": { |
|
|
|
|
|
"listen": [ |
|
|
|
|
|
":8080" |
|
|
|
|
|
], |
|
|
|
|
|
"routes": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"handle": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"handler": "rewrite", |
|
|
|
|
|
"method": "FOO" |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
@ -27,6 +27,7 @@ import ( |
|
|
|
|
|
|
|
|
func init() { |
|
|
func init() { |
|
|
httpcaddyfile.RegisterHandlerDirective("rewrite", parseCaddyfileRewrite) |
|
|
httpcaddyfile.RegisterHandlerDirective("rewrite", parseCaddyfileRewrite) |
|
|
|
|
|
httpcaddyfile.RegisterHandlerDirective("method", parseCaddyfileMethod) |
|
|
httpcaddyfile.RegisterHandlerDirective("uri", parseCaddyfileURI) |
|
|
httpcaddyfile.RegisterHandlerDirective("uri", parseCaddyfileURI) |
|
|
httpcaddyfile.RegisterDirective("handle_path", parseCaddyfileHandlePath) |
|
|
httpcaddyfile.RegisterDirective("handle_path", parseCaddyfileHandlePath) |
|
|
} |
|
|
} |
|
@ -51,6 +52,24 @@ func parseCaddyfileRewrite(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, |
|
|
return rewr, nil |
|
|
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
|
|
|
// parseCaddyfileURI sets up a handler for manipulating (but not "rewriting") the
|
|
|
// URI from Caddyfile tokens. Syntax:
|
|
|
// URI from Caddyfile tokens. Syntax:
|
|
|
//
|
|
|
//
|
|
|