Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
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.
Matthew Holt committed
Jan 22, 2020 at 09:36 UTC
0742530d3d8c602c5d42115606ae0e05b577f3e9
1 file changed
+4
modules/caddyhttp/rewrite/caddyfile.go
+4
@@ -16,6 +16,7 @@ package rewrite
16
17
import (
18
"strconv"
19
+ "strings"
20
21
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
22
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
@@ -60,6 +61,9 @@ func parseCaddyfileStripPrefix(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHand
61
return nil, h.ArgErr()
62
}
63
rewr.StripPathPrefix = h.Val()
64
+ if !strings.HasPrefix(rewr.StripPathPrefix, "/") {
65
+ rewr.StripPathPrefix = "/" + rewr.StripPathPrefix
66
+ }
67
if h.NextArg() {
68
return nil, h.ArgErr()
69
}