Define interface for HTTP router; remove path canonicalization #521
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor some of the interfaces around HTTP router to match better with the standard library in anticipation of having to fork or replace
julienschmidt/httprouter
.Fixed
HTTPRouter.Handle
(previouslyRegister
) will now return an error in all cases where the router detects that the registered route has a conflict, rather than sometimes error and sometimes panic.Changed
HTTPRequest.Params
) switched fromhttprouter.Params
tourl.Values
from the standard library. Theurl.Values
type is explicitly designed for this purpose and also provides a faster lookup by key thanhttprouter.Params
due to being a map rather than list.httpRouter
) and replaced with an interface:This will be the HTTP router interface we can swap out the implementation of from
julienschmidt/httprouter
to something likegorilla/mux
or even standard libraryhttp.ServeMux
.RouterEndpoint.HandleRequest
function signature removedparams
parameter in lieu of getting the parameters from the context on thehttp.Request
. This is to makeHandleRequest
transformable tohttp.Handler
viahttp.HandlerFunc
by making it matchfunc(w http.ResponseWriter, r *http.Request)
.Removed
RedirectTrailingSlash
flag ofjulienschmidt/httprouter
which issues a redirect. For example, when registering/foo/bar
, if you request/foo/bar/
it will issue a 301 to/foo/bar
. The existing logic to canonicalize the paths was incomplete (it didn't detect that/a/:b
and/a/:c
are the same for purposes of the router) and it is unclear if this is a requirement.