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.
* 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
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