-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route.Host -matching will ignore any provided port from getHost(), if… #447
Conversation
… a port isn't specified in the template In lieu of checking the template pattern on every Match request, a bool is added to the routeRegexp, and set if the routeRegexp is a host AND there is no ":" in the template. I dislike extending the type, but I'd dislike doing a string match on every single Match, even more.
works for me |
This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days. |
Sorry, I missed this: can you show application code before/after that explains this better? I understand what the change does, but not why. |
@elithrar |
As @yogo1212 properly described, a previous PR #383 horrifically broke a good swath of the Gorilla-using Internet by deciding that if you didn't specify a port in the route, you can't specify a port on the Request and have it match. This PR allows that PR to exist in-spirit, without the awful requirement of specifying ports for every route. Without either reverting #383 or implementing this patch, if your route is r.Host("a.b.c") then http://a.b.c:80/ won't work but http://a.b.c/ will. With this patch, unless you specify the port on the route, it assumes you don't give a flying leap what port the request tacks on. |
Understood - #383 broke more than we anticipated (users should pin + test deps, but we also need to do a better job of checking impact). Reviewing the PR today and can (hopefully) merge + tag a new version tonight. |
@elithrar thank you for the notice <3 |
full diff: gorilla/mux@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>
full diff: gorilla/mux@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>
full diff: gorilla/mux@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> Upstream-commit: 25b451e01b8a1b44f45a67cb4731ff61d7b1ebc1 Component: engine
full diff: gorilla/mux@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 25b451e) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: gorilla/mux@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> Upstream-commit: 81e3457c23630de470c42d909e79dfb159833f7a Component: cli
full diff: gorilla/mux@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>
full diff: gorilla/mux@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 25b451e) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: gorilla/mux@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> Upstream-commit: 486953e2ff065883897746317c318b0bb8d3406d Component: engine
full diff: gorilla/mux@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> Signed-off-by: zach <Zachary.Joyner@linux.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR actually caused a regression one more change needed is missing in this PR
git diff
diff --git a/regexp.go b/regexp.go
index 96dd94a..0144842 100644
--- a/regexp.go
+++ b/regexp.go
@@ -325,6 +325,12 @@ func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
// Store host variables.
if v.host != nil {
host := getHost(req)
+ if v.host.wildcardHostPort {
+ // Don't be strict on the port match
+ if i := strings.Index(host, ":"); i != -1 {
+ host = host[:i]
+ }
+ }
matches := v.host.regexp.FindStringSubmatchIndex(host)
if len(matches) > 0 {
extractVars(host, matches, v.host.varsN, m.Vars)
Continuing from PR gorilla#447 we have to add extra check to ignore the port as well
Continuing from PR gorilla#447 we have to add extra check to ignore the port as well add tests to cover this case
Continuing from PR #447 we have to add extra check to ignore the port as well add tests to cover this case
… a port isn't specified in the template
In lieu of checking the template pattern on every Match request, a bool is added to the routeRegexp, and set if the routeRegexp is a host AND there is no ":" in the template. I dislike extending the type, but I'd dislike doing a string match on every single Match, even more.
All existing mux tests pass. Additionally my application-level (Convey) positive and negative tests pass. Feel free to comment: You know your code better than I do.