From a8f02c8b889fd11bdae75b210e03a28c83b3af27 Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Tue, 9 Mar 2021 07:55:39 +0200 Subject: [PATCH] Clarify why rewriteURL is trimming prefix --- middleware/middleware.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/middleware/middleware.go b/middleware/middleware.go index 1c0b5943b..a7ad73a5c 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -53,6 +53,8 @@ func rewriteURL(rewriteRegex map[*regexp.Regexp]string, req *http.Request) error return nil } + // Depending how HTTP request is sent RequestURI could contain Scheme://Host/path or be just /path. + // We only want to use path part for rewriting and therefore trim prefix if it exists rawURI := req.RequestURI if rawURI != "" && rawURI[0] != '/' { prefix := "" @@ -60,7 +62,7 @@ func rewriteURL(rewriteRegex map[*regexp.Regexp]string, req *http.Request) error prefix = req.URL.Scheme + "://" } if req.URL.Host != "" { - prefix += req.URL.Host + prefix += req.URL.Host // host or host:port } if prefix != "" { rawURI = strings.TrimPrefix(rawURI, prefix)