diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-22 09:36:05 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-22 09:36:05 -0700 |
commit | 0742530d3d8c602c5d42115606ae0e05b577f3e9 (patch) | |
tree | 67e468679b67df527e2cbb76950fc639553b7ea2 /modules | |
parent | 6b6cd934d02476e3d71b85edbb0acf58cf299fec (diff) |
rewrite: Prepend "/" if missing from strip path prefix
Paths always begin with a slash, and omitting the leading slash could be
convenient to avoid confusion with a path matcher in the Caddyfile. I do
not think there would be any harm to implicitly add the leading slash.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/rewrite/caddyfile.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/modules/caddyhttp/rewrite/caddyfile.go b/modules/caddyhttp/rewrite/caddyfile.go index 6ec51c0..e69ea21 100644 --- a/modules/caddyhttp/rewrite/caddyfile.go +++ b/modules/caddyhttp/rewrite/caddyfile.go @@ -16,6 +16,7 @@ package rewrite import ( "strconv" + "strings" "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile" "github.com/caddyserver/caddy/v2/modules/caddyhttp" @@ -60,6 +61,9 @@ func parseCaddyfileStripPrefix(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHand return nil, h.ArgErr() } rewr.StripPathPrefix = h.Val() + if !strings.HasPrefix(rewr.StripPathPrefix, "/") { + rewr.StripPathPrefix = "/" + rewr.StripPathPrefix + } if h.NextArg() { return nil, h.ArgErr() } |