mirror of https://github.com/caddyserver/caddy.git
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.
This commit is contained in:
parent
6b6cd934d0
commit
0742530d3d
|
@ -16,6 +16,7 @@ package rewrite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
|
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||||
|
@ -60,6 +61,9 @@ func parseCaddyfileStripPrefix(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHand
|
||||||
return nil, h.ArgErr()
|
return nil, h.ArgErr()
|
||||||
}
|
}
|
||||||
rewr.StripPathPrefix = h.Val()
|
rewr.StripPathPrefix = h.Val()
|
||||||
|
if !strings.HasPrefix(rewr.StripPathPrefix, "/") {
|
||||||
|
rewr.StripPathPrefix = "/" + rewr.StripPathPrefix
|
||||||
|
}
|
||||||
if h.NextArg() {
|
if h.NextArg() {
|
||||||
return nil, h.ArgErr()
|
return nil, h.ArgErr()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue