Comment for CurrentRoute claimed that setting the KeepContext option would propagate
the Route even after the request. The KeepContext option is deprecated and has no effect.
A production server is seeing a significant amount of allocations in (*routeRegexp).getURLQuery
Since it is only interested in a single value and only the first value we create a specialized function for that.
Comparing a few parameter parsing scenarios:
```
Benchmark_findQueryKey/0-8 7184014 168 ns/op 0 B/op 0 allocs/op
Benchmark_findQueryKey/1-8 5307873 227 ns/op 48 B/op 3 allocs/op
Benchmark_findQueryKey/2-8 1560836 770 ns/op 483 B/op 10 allocs/op
Benchmark_findQueryKey/3-8 1296200 931 ns/op 559 B/op 11 allocs/op
Benchmark_findQueryKey/4-8 666502 1769 ns/op 3 B/op 1 allocs/op
Benchmark_findQueryKeyGoLib/0-8 1740973 690 ns/op 864 B/op 8 allocs/op
Benchmark_findQueryKeyGoLib/1-8 3029618 393 ns/op 432 B/op 4 allocs/op
Benchmark_findQueryKeyGoLib/2-8 461427 2511 ns/op 1542 B/op 24 allocs/op
Benchmark_findQueryKeyGoLib/3-8 324252 3804 ns/op 1984 B/op 28 allocs/op
Benchmark_findQueryKeyGoLib/4-8 69348 14928 ns/op 12716 B/op 130 allocs/op
```
* 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
* Add documentation for using mux to serve a SPA
* r -> router to prevent shadowing
* Expand SPA acronym
* BrowserRouter link
* Add more comments to explain how the spaHandler.ServeHTTP method works
* More sensical CORSMethodMiddleware
* Only sets Access-Control-Allow-Methods on valid preflight requests
* Does not return after setting the Access-Control-Allow-Methods header
* Does not append OPTIONS header to Access-Control-Allow-Methods
regardless of whether there is an OPTIONS method matcher
* Adds tests for the listed behavior
* Add example for CORSMethodMiddleware
* Do not check for preflight and add documentation to the README
* Use http.MethodOptions instead of "OPTIONS"
* Add link to CORSMethodMiddleware section to readme
* Add test for unmatching route methods
* Rename CORS Method Middleware to Handling CORS Requests in README
* Link CORSMethodMiddleware in README to godoc
* Break CORSMethodMiddleware doc into bullets for readability
* Add comment about specifying OPTIONS to example in README for CORSMethodMiddleware
* Document cURL command used for testing CORS Method Middleware
* Update comment in example to "Handle the request"
* Add explicit comment about OPTIONS matchers to CORSMethodMiddleware doc
* Update circleci config to only check gofmt diff on latest go version
* Break up gofmt and go vet checks into separate steps.
* Use canonical circleci config
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.
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