Browse Source

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.
master
Matthew Holt 5 years ago
parent
commit
0742530d3d
No known key found for this signature in database GPG Key ID: 2A349DD577D586A5
  1. 4
      modules/caddyhttp/rewrite/caddyfile.go

4
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()
}

Loading…
Cancel
Save