summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/v4/middleware/util.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-06-16 23:33:25 +0200
committerGitHub <noreply@github.com>2019-06-16 23:33:25 +0200
commitcb712ff37d3c20a21695e00c52fff213a6fd40b4 (patch)
tree0ba0ee4f55bf6ace2656562465cc82d807e741b9 /vendor/github.com/labstack/echo/v4/middleware/util.go
parentf4ae61044888f591830e6c1be9a2bdb14f88943e (diff)
downloadmatterbridge-msglm-cb712ff37d3c20a21695e00c52fff213a6fd40b4.tar.gz
matterbridge-msglm-cb712ff37d3c20a21695e00c52fff213a6fd40b4.tar.bz2
matterbridge-msglm-cb712ff37d3c20a21695e00c52fff213a6fd40b4.zip
Update vendor (#852)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/middleware/util.go')
-rw-r--r--vendor/github.com/labstack/echo/v4/middleware/util.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/labstack/echo/v4/middleware/util.go b/vendor/github.com/labstack/echo/v4/middleware/util.go
new file mode 100644
index 00000000..ab951a0e
--- /dev/null
+++ b/vendor/github.com/labstack/echo/v4/middleware/util.go
@@ -0,0 +1,54 @@
+package middleware
+
+import (
+ "strings"
+)
+
+func matchScheme(domain, pattern string) bool {
+ didx := strings.Index(domain, ":")
+ pidx := strings.Index(pattern, ":")
+ return didx != -1 && pidx != -1 && domain[:didx] == pattern[:pidx]
+}
+
+// matchSubdomain compares authority with wildcard
+func matchSubdomain(domain, pattern string) bool {
+ if !matchScheme(domain, pattern) {
+ return false
+ }
+ didx := strings.Index(domain, "://")
+ pidx := strings.Index(pattern, "://")
+ if didx == -1 || pidx == -1 {
+ return false
+ }
+ domAuth := domain[didx+3:]
+ // to avoid long loop by invalid long domain
+ if len(domAuth) > 253 {
+ return false
+ }
+ patAuth := pattern[pidx+3:]
+
+ domComp := strings.Split(domAuth, ".")
+ patComp := strings.Split(patAuth, ".")
+ for i := len(domComp)/2 - 1; i >= 0; i-- {
+ opp := len(domComp) - 1 - i
+ domComp[i], domComp[opp] = domComp[opp], domComp[i]
+ }
+ for i := len(patComp)/2 - 1; i >= 0; i-- {
+ opp := len(patComp) - 1 - i
+ patComp[i], patComp[opp] = patComp[opp], patComp[i]
+ }
+
+ for i, v := range domComp {
+ if len(patComp) <= i {
+ return false
+ }
+ p := patComp[i]
+ if p == "*" {
+ return true
+ }
+ if p != v {
+ return false
+ }
+ }
+ return false
+}