Skip to content

Commit

Permalink
Clarify why rewriteURL is trimming prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Mar 9, 2021
1 parent 24dbea4 commit a8f02c8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ 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 := ""
if req.URL.Scheme != "" {
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)
Expand Down

0 comments on commit a8f02c8

Please # to comment.