summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/v4/middleware/middleware.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-03-20 22:40:23 +0100
committerGitHub <noreply@github.com>2021-03-20 22:40:23 +0100
commitee5d9b43b54a3becf3cb4025198f24608d35500d (patch)
treedd3614db7423da52f5a71da3001e48d1e4195ea1 /vendor/github.com/labstack/echo/v4/middleware/middleware.go
parent3a8857c8c9efb2c67fb8c175f31d2b9c617b771b (diff)
downloadmatterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.gz
matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.bz2
matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.zip
Update vendor (#1414)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/middleware/middleware.go')
-rw-r--r--vendor/github.com/labstack/echo/v4/middleware/middleware.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/labstack/echo/v4/middleware/middleware.go b/vendor/github.com/labstack/echo/v4/middleware/middleware.go
index d0b7153c..6bdb0eb7 100644
--- a/vendor/github.com/labstack/echo/v4/middleware/middleware.go
+++ b/vendor/github.com/labstack/echo/v4/middleware/middleware.go
@@ -1,6 +1,8 @@
package middleware
import (
+ "net/http"
+ "net/url"
"regexp"
"strconv"
"strings"
@@ -32,6 +34,47 @@ func captureTokens(pattern *regexp.Regexp, input string) *strings.Replacer {
return strings.NewReplacer(replace...)
}
+func rewriteRulesRegex(rewrite map[string]string) map[*regexp.Regexp]string {
+ // Initialize
+ rulesRegex := map[*regexp.Regexp]string{}
+ for k, v := range rewrite {
+ k = regexp.QuoteMeta(k)
+ k = strings.Replace(k, `\*`, "(.*?)", -1)
+ if strings.HasPrefix(k, `\^`) {
+ k = strings.Replace(k, `\^`, "^", -1)
+ }
+ k = k + "$"
+ rulesRegex[regexp.MustCompile(k)] = v
+ }
+ 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
+ }
+
+ continue
+ }
+
+ if replacer := captureTokens(k, req.URL.Path); replacer != nil {
+ req.URL.Path = replacer.Replace(v)
+
+ return // rewrite only once
+ }
+ }
+}
+
// DefaultSkipper returns false which processes the middleware.
func DefaultSkipper(echo.Context) bool {
return false