-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SkipUrlClean by not using DefaultServeMux
The issue itself happen because we wrap `gorilla.Mux` router through `http.ServeMux`, which is kinda wrong, because `Mux` is already a `ServeMux` implementation. So we processing routes twice. Default `ServeMux` implementation have own route sanitization logic, and can’t be configured with `SkipClean` option, like gorilla implementation. The solution here is to stop using ServeMux and use Gorilla directly. Problem with this approach is that we need to reload, eg. replace, the router inside `doReload` function. Neither gorilla or ServeMux support replacing the routes, so replacing the whole router object is the only solution. When we pass raw Gorilla Router object to the `Server.Handler`, and replace `mainRouter` in `doReload`, server do not see the changes: thats why we had issues when API reloads was not working. There are 2 ways to solve this issue: expose server object as a global variable, and dynamically replace `Handler` attribute, or write simple `http.Handler` wrapper around `mainRouter`, which always calls the current router. I’m not sure about safety of this approach but since previously we replaced `DefaultServeMux` directly, and had no any issues, I may assume that it should be thread safe. Should fix #1093
- Loading branch information
Showing
2 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters