Bläddra i källkod

Merge pull request #39381 from thaJeztah/bump_gorilla_mux

bump gorilla/mux v1.7.2
Brian Goff 6 år sedan
förälder
incheckning
a50869f077

+ 1 - 1
vendor.conf

@@ -5,7 +5,7 @@ github.com/docker/libtrust                          9cbd2a1374f46905c68a4eb3694a
 github.com/go-check/check                           4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
 github.com/go-check/check                           4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
 github.com/golang/gddo                              9b12a26f3fbd7397dee4e20939ddca719d840d2a
 github.com/golang/gddo                              9b12a26f3fbd7397dee4e20939ddca719d840d2a
 github.com/google/uuid                              0cd6bf5da1e1c83f8b45653022c74f71af0538a4 # v1.1.1
 github.com/google/uuid                              0cd6bf5da1e1c83f8b45653022c74f71af0538a4 # v1.1.1
-github.com/gorilla/mux                              a7962380ca08b5a188038c69871b8d3fbdf31e89 # v1.7.0
+github.com/gorilla/mux                              ed099d42384823742bba0bf9a72b53b55c9e2e38 # v1.7.2
 github.com/Microsoft/opengcs                        a10967154e143a36014584a6f664344e3bb0aa64
 github.com/Microsoft/opengcs                        a10967154e143a36014584a6f664344e3bb0aa64
 
 
 github.com/konsorten/go-windows-terminal-sequences  f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2
 github.com/konsorten/go-windows-terminal-sequences  f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2

+ 6 - 0
vendor/github.com/gorilla/mux/mux.go

@@ -283,6 +283,12 @@ func (r *Router) NewRoute() *Route {
 	return route
 	return route
 }
 }
 
 
+// Name registers a new route with a name.
+// See Route.Name().
+func (r *Router) Name(name string) *Route {
+	return r.NewRoute().Name(name)
+}
+
 // Handle registers a new route with a matcher for the URL path.
 // Handle registers a new route with a matcher for the URL path.
 // See Route.Path() and Route.Handler().
 // See Route.Path() and Route.Handler().
 func (r *Router) Handle(path string, handler http.Handler) *Route {
 func (r *Router) Handle(path string, handler http.Handler) *Route {

+ 27 - 10
vendor/github.com/gorilla/mux/regexp.go

@@ -113,6 +113,13 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro
 	if typ != regexpTypePrefix {
 	if typ != regexpTypePrefix {
 		pattern.WriteByte('$')
 		pattern.WriteByte('$')
 	}
 	}
+
+	var wildcardHostPort bool
+	if typ == regexpTypeHost {
+		if !strings.Contains(pattern.String(), ":") {
+			wildcardHostPort = true
+		}
+	}
 	reverse.WriteString(raw)
 	reverse.WriteString(raw)
 	if endSlash {
 	if endSlash {
 		reverse.WriteByte('/')
 		reverse.WriteByte('/')
@@ -131,13 +138,14 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro
 
 
 	// Done!
 	// Done!
 	return &routeRegexp{
 	return &routeRegexp{
-		template:   template,
-		regexpType: typ,
-		options:    options,
-		regexp:     reg,
-		reverse:    reverse.String(),
-		varsN:      varsN,
-		varsR:      varsR,
+		template:         template,
+		regexpType:       typ,
+		options:          options,
+		regexp:           reg,
+		reverse:          reverse.String(),
+		varsN:            varsN,
+		varsR:            varsR,
+		wildcardHostPort: wildcardHostPort,
 	}, nil
 	}, nil
 }
 }
 
 
@@ -158,11 +166,22 @@ type routeRegexp struct {
 	varsN []string
 	varsN []string
 	// Variable regexps (validators).
 	// Variable regexps (validators).
 	varsR []*regexp.Regexp
 	varsR []*regexp.Regexp
+	// Wildcard host-port (no strict port match in hostname)
+	wildcardHostPort bool
 }
 }
 
 
 // Match matches the regexp against the URL host or path.
 // Match matches the regexp against the URL host or path.
 func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
 func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
-	if r.regexpType != regexpTypeHost {
+	if r.regexpType == regexpTypeHost {
+		host := getHost(req)
+		if r.wildcardHostPort {
+			// Don't be strict on the port match
+			if i := strings.Index(host, ":"); i != -1 {
+				host = host[:i]
+			}
+		}
+		return r.regexp.MatchString(host)
+	} else {
 		if r.regexpType == regexpTypeQuery {
 		if r.regexpType == regexpTypeQuery {
 			return r.matchQueryString(req)
 			return r.matchQueryString(req)
 		}
 		}
@@ -172,8 +191,6 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
 		}
 		}
 		return r.regexp.MatchString(path)
 		return r.regexp.MatchString(path)
 	}
 	}
-
-	return r.regexp.MatchString(getHost(req))
 }
 }
 
 
 // url builds a URL part using the given values.
 // url builds a URL part using the given values.

+ 1 - 1
vendor/github.com/gorilla/mux/route.go

@@ -383,7 +383,7 @@ func (r *Route) PathPrefix(tpl string) *Route {
 // The above route will only match if the URL contains the defined queries
 // The above route will only match if the URL contains the defined queries
 // values, e.g.: ?foo=bar&id=42.
 // values, e.g.: ?foo=bar&id=42.
 //
 //
-// It the value is an empty string, it will match any value if the key is set.
+// If the value is an empty string, it will match any value if the key is set.
 //
 //
 // Variables can define an optional regexp pattern to be matched:
 // Variables can define an optional regexp pattern to be matched:
 //
 //