From 0742530d3d8c602c5d42115606ae0e05b577f3e9 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 22 Jan 2020 09:36:05 -0700 Subject: [PATCH] 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. --- modules/caddyhttp/rewrite/caddyfile.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/caddyhttp/rewrite/caddyfile.go b/modules/caddyhttp/rewrite/caddyfile.go index 6ec51c0d..e69ea212 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() }