This changes RouteMatch so it contains a slice of the methods that would
have been accepted. That slice is then used to populate the Allow header
accordingly.
This makes the default behavior of mux when returning 405 Method Not
Allowed compliant with [RFC 7231§6.5.5][RFC7231].
[RFC7231]: https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.5
* 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, 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
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.
* 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.
By default paths are run through the cleanPath method which prevents
using fancier paths like /fetch/http://xkcd.com/534
This adds a SkipClean option so that this path isn't redirected to
/fetch/http/xkcd.com/534
Issue #16: Added regex support for matching headers
Issue #16 : Addressed code review and refactored support for regex into
a separate function
Added compiled regex to route matcher
Issue #16: Added regex support for matching headers
Issue #16 : Addressed code review and refactored support for regex into
a separate function
Added compiled regex to route matcher