full diff: https://github.com/gorilla/mux/compare/v1.7.0...v1.7.2
includes:
- gorilla/mux#457 adding Router.Name to create new Route
- gorilla/mux#447 host:port matching does not require a :port to be specified
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 25b451e01b8a1b44f45a67cb4731ff61d7b1ebc1)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
... | ... |
@@ -5,7 +5,7 @@ github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a |
5 | 5 |
github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git |
6 | 6 |
github.com/golang/gddo 9b12a26f3fbd7397dee4e20939ddca719d840d2a |
7 | 7 |
github.com/google/uuid 0cd6bf5da1e1c83f8b45653022c74f71af0538a4 # v1.1.1 |
8 |
-github.com/gorilla/mux a7962380ca08b5a188038c69871b8d3fbdf31e89 # v1.7.0 |
|
8 |
+github.com/gorilla/mux ed099d42384823742bba0bf9a72b53b55c9e2e38 # v1.7.2 |
|
9 | 9 |
github.com/Microsoft/opengcs a10967154e143a36014584a6f664344e3bb0aa64 |
10 | 10 |
|
11 | 11 |
github.com/creack/pty 2769f65a3a94eb8f876f44a0459d24ae7ad2e488 # v1.1.7 |
... | ... |
@@ -283,6 +283,12 @@ func (r *Router) NewRoute() *Route { |
283 | 283 |
return route |
284 | 284 |
} |
285 | 285 |
|
286 |
+// Name registers a new route with a name. |
|
287 |
+// See Route.Name(). |
|
288 |
+func (r *Router) Name(name string) *Route { |
|
289 |
+ return r.NewRoute().Name(name) |
|
290 |
+} |
|
291 |
+ |
|
286 | 292 |
// Handle registers a new route with a matcher for the URL path. |
287 | 293 |
// See Route.Path() and Route.Handler(). |
288 | 294 |
func (r *Router) Handle(path string, handler http.Handler) *Route { |
... | ... |
@@ -113,6 +113,13 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro |
113 | 113 |
if typ != regexpTypePrefix { |
114 | 114 |
pattern.WriteByte('$') |
115 | 115 |
} |
116 |
+ |
|
117 |
+ var wildcardHostPort bool |
|
118 |
+ if typ == regexpTypeHost { |
|
119 |
+ if !strings.Contains(pattern.String(), ":") { |
|
120 |
+ wildcardHostPort = true |
|
121 |
+ } |
|
122 |
+ } |
|
116 | 123 |
reverse.WriteString(raw) |
117 | 124 |
if endSlash { |
118 | 125 |
reverse.WriteByte('/') |
... | ... |
@@ -131,13 +138,14 @@ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*ro |
131 | 131 |
|
132 | 132 |
// Done! |
133 | 133 |
return &routeRegexp{ |
134 |
- template: template, |
|
135 |
- regexpType: typ, |
|
136 |
- options: options, |
|
137 |
- regexp: reg, |
|
138 |
- reverse: reverse.String(), |
|
139 |
- varsN: varsN, |
|
140 |
- varsR: varsR, |
|
134 |
+ template: template, |
|
135 |
+ regexpType: typ, |
|
136 |
+ options: options, |
|
137 |
+ regexp: reg, |
|
138 |
+ reverse: reverse.String(), |
|
139 |
+ varsN: varsN, |
|
140 |
+ varsR: varsR, |
|
141 |
+ wildcardHostPort: wildcardHostPort, |
|
141 | 142 |
}, nil |
142 | 143 |
} |
143 | 144 |
|
... | ... |
@@ -158,11 +166,22 @@ type routeRegexp struct { |
158 | 158 |
varsN []string |
159 | 159 |
// Variable regexps (validators). |
160 | 160 |
varsR []*regexp.Regexp |
161 |
+ // Wildcard host-port (no strict port match in hostname) |
|
162 |
+ wildcardHostPort bool |
|
161 | 163 |
} |
162 | 164 |
|
163 | 165 |
// Match matches the regexp against the URL host or path. |
164 | 166 |
func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool { |
165 |
- if r.regexpType != regexpTypeHost { |
|
167 |
+ if r.regexpType == regexpTypeHost { |
|
168 |
+ host := getHost(req) |
|
169 |
+ if r.wildcardHostPort { |
|
170 |
+ // Don't be strict on the port match |
|
171 |
+ if i := strings.Index(host, ":"); i != -1 { |
|
172 |
+ host = host[:i] |
|
173 |
+ } |
|
174 |
+ } |
|
175 |
+ return r.regexp.MatchString(host) |
|
176 |
+ } else { |
|
166 | 177 |
if r.regexpType == regexpTypeQuery { |
167 | 178 |
return r.matchQueryString(req) |
168 | 179 |
} |
... | ... |
@@ -172,8 +191,6 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool { |
172 | 172 |
} |
173 | 173 |
return r.regexp.MatchString(path) |
174 | 174 |
} |
175 |
- |
|
176 |
- return r.regexp.MatchString(getHost(req)) |
|
177 | 175 |
} |
178 | 176 |
|
179 | 177 |
// url builds a URL part using the given values. |
... | ... |
@@ -383,7 +383,7 @@ func (r *Route) PathPrefix(tpl string) *Route { |
383 | 383 |
// The above route will only match if the URL contains the defined queries |
384 | 384 |
// values, e.g.: ?foo=bar&id=42. |
385 | 385 |
// |
386 |
-// It the value is an empty string, it will match any value if the key is set. |
|
386 |
+// If the value is an empty string, it will match any value if the key is set. |
|
387 | 387 |
// |
388 | 388 |
// Variables can define an optional regexp pattern to be matched: |
389 | 389 |
// |