MatchErr is set by the router to ErrNotFound if no route matches. If
no route of a Subrouter matches the error can by safely ignored. This
implementation only ignores these errors and does not ignore other
errors like ErrMethodMismatch.
Previously, getHost only returned the host. As it now returns the
port as well, any .Host matches on a route will need to be updated
to also support matching on the port for cases where the port is
non default, eg: 80 for http or 443 for https.
Previously, when searching for a match, matchErr would be erroneously set, and prevent middleware from running (no match == no middleware runs).
This fix clears matchErr before traversing the next subrouter in a multi-subrouter router.
* Pull out common shared `routeConf` so that config is pushed on to child
routers and routes.
* Removes obsolete usages of `parentRoute`
* Add tests defining compositional behavior
* Exercise `copyRouteConf` for posterity
The example in the README does not pass the request through a mux therefore the request variables from the path are never populated. Update the sample to create a minimum viable router to use.
Fixes#373
CORSMethodMiddleware sets the Access-Control-Allow-Methods response header
on a request, by matching routes based only on paths. It also handles
OPTIONS requests, by settings Access-Control-Allow-Methods, and then
returning without calling the next HTTP handler.
Prior to this change, the example documentation
found in the README.md has an errant code which
won't work in the table-driven code example.
This change modifies the variable name from `t` to `tc`
so it does not conflict with the `t *testing.T` struct
definition.
* Adds a range clause to the `for` statement
* Modifies `for` statement scope to use `tc.shouldPass`, and `tc.routeVariable`
Doc: https://github.com/gorilla/mux#testing-handlers
* [docs] Clarify SetURLVars
Clarify in documentation that SetURLVars does not modify the given
*htttp.Request, provide an example of usage.
* Short and sweet function doc, example test.
They actually return an error instead of an empty list. `GetMethods` happened to not return an error, but it should for consistency, so I added that as well.
The existing options matchPrefix, matchHost, and matchQueries are
mutually exclusive so there's no point in having a separate boolean
argument for each one. It's clearer if there's a single type variable.
strictSlash and useEncodedPath were also being passed as naked bools so
I've wrapped these in a struct called routeRegexpOptions for more clarity
at the call site.
* Add a function to set url params for test
* [docs] add justification for SetURLVars and description of alternative approach to setting url vars.
* rename SetURLParams to SetURLVars as this is more descriptive.
* rename testing to testing_helpers as this is more descriptive.
* [docs] add stipulation to SetURLVars that it should only be used for testing purposes
* [docs] Note StrictSlash re-direct behaviour #308
* StrictSlash enabled routes return a 301 to the client
* As per the HTTP standards, non-idempotent methods, such as POST or PUT, will be followed with a GET by the client
* Users should use middleware if they wish to change this behaviour to return a HTTP 308.
* Update description of StrictSlash
* Test method-based subrouters for multiple matching paths
* Pass TestMethodsSubrouter
* Change http.Method* constants to string literals
- Make compatible with Go v1.5
* Make TestMethodsSubrouter stateless and concurrent
* Remove t.Run and break up tests for concurrency
* Use backticks to remove quote escaping
* Remove global method handlers and HTTP method constants