diff options
author | Wim <wim@42.be> | 2021-05-05 22:03:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-05 22:03:28 +0200 |
commit | a0bca42a7ad98a37f4bdc4d7adc419471163edfb (patch) | |
tree | 3e87fdb61128039b016adb4e586636484c63ed52 /vendor/github.com/labstack/echo/v4/middleware/middleware.go | |
parent | af543dcd05cfb5341311e2e214727e26411d2f92 (diff) | |
download | matterbridge-msglm-a0bca42a7ad98a37f4bdc4d7adc419471163edfb.tar.gz matterbridge-msglm-a0bca42a7ad98a37f4bdc4d7adc419471163edfb.tar.bz2 matterbridge-msglm-a0bca42a7ad98a37f4bdc4d7adc419471163edfb.zip |
Update vendor (#1461)
* Update vendored libs
* Fix slack api changes
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/middleware/middleware.go')
-rw-r--r-- | vendor/github.com/labstack/echo/v4/middleware/middleware.go | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/vendor/github.com/labstack/echo/v4/middleware/middleware.go b/vendor/github.com/labstack/echo/v4/middleware/middleware.go index 6bdb0eb7..a7ad73a5 100644 --- a/vendor/github.com/labstack/echo/v4/middleware/middleware.go +++ b/vendor/github.com/labstack/echo/v4/middleware/middleware.go @@ -2,7 +2,6 @@ package middleware import ( "net/http" - "net/url" "regexp" "strconv" "strings" @@ -49,30 +48,39 @@ func rewriteRulesRegex(rewrite map[string]string) map[*regexp.Regexp]string { return rulesRegex } -func rewritePath(rewriteRegex map[*regexp.Regexp]string, req *http.Request) { - for k, v := range rewriteRegex { - rawPath := req.URL.RawPath - if rawPath != "" { - // RawPath is only set when there has been escaping done. In that case Path must be deduced from rewritten RawPath - // because encoded Path could match rules that RawPath did not - if replacer := captureTokens(k, rawPath); replacer != nil { - rawPath = replacer.Replace(v) - - req.URL.RawPath = rawPath - req.URL.Path, _ = url.PathUnescape(rawPath) - - return // rewrite only once - } +func rewriteURL(rewriteRegex map[*regexp.Regexp]string, req *http.Request) error { + if len(rewriteRegex) == 0 { + return nil + } - continue + // 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 // host or host:port + } + if prefix != "" { + rawURI = strings.TrimPrefix(rawURI, prefix) + } + } - if replacer := captureTokens(k, req.URL.Path); replacer != nil { - req.URL.Path = replacer.Replace(v) + for k, v := range rewriteRegex { + if replacer := captureTokens(k, rawURI); replacer != nil { + url, err := req.URL.Parse(replacer.Replace(v)) + if err != nil { + return err + } + req.URL = url - return // rewrite only once + return nil // rewrite only once } } + return nil } // DefaultSkipper returns false which processes the middleware. |