* Remove context helpers in context.go
* Update request context funcs to take concrete types
* Move TestNativeContextMiddleware to mux_test.go
* Clarify KeepContext Go 1.7+ comment
Mux doesn't build on Go < 1.7 so the comment doesn't really need to
clarify anymore.
* Guess the scheme if r.URL.Scheme is unset
It's not expected that the request's URL is fully populated when used on
the server-side (it's more of a client-side field), so we shouldn't
expect it to be present.
In practice, it's only rarely set at all on the server, making mux's
`Schemes` matcher tricky to use as it is.
This commit adds a test which would have failed before demonstrating the
problem, as well as a fix which I think makes `.Schemes` match what
users expect.
* [doc] Add more detail to Schemes and URL godocs
* Add route url test for schemes
* Make httpserver test use more specific scheme matchers
* Update test to have different responses per route
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.
* 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
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.
* [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.
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.
* 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
* Move misplaced tests and fix comments.
* Support building URLs with non-http schemes.
- Capture first scheme configured for a route for use when building
URLs.
- Add new Route.URLScheme method similar to URLHost and URLPath.
- Update Route.URLHost and Route.URL to use the captured scheme if
present.
* Remove Route.URLScheme method.
* Remove UTF-8 BOM.
* Add mechanism to route based on the escaped path, correct request mocking in tests
* Remove unneccessary regex matching, substitute with string slicing
* Add test case and handling for requests with no host/scheme
This test focuses on the feature of allowing sub-routers error handlers to precede the parents, rather than the code change required to provide this functionality.