-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cleanPath() causing a change in the URL should not necessarily cause a redirect #94
Comments
I agree with your reasoning. Granted, the client is hitting the endpoint incorrectly. However path.Clean doesn't just trim trailing slashes (as code comments say https://github.com/gorilla/mux/blob/master/mux.go#L348), it trims all extra slashes and in some cases dots too... because it is meant more for filesystem pathing IMO. Perhaps a better approach ( don't know the exact rationale for the current implementation) is logic surrounding StrictSlash and https://golang.org/pkg/strings/#TrimRight with "/" as the cutset... |
The |
and actually the redirect behaviour is basically the same as well... so I'm not really inclined to change the way it is working right now |
Since I've started using Traefik -- which enlists gorilla/mux in its routing layer -- I've discovered two backend apps that no longer function as designed. They both use urls with their proxy data in the path, as opposed to a query-string. For example:
While I don't personally agree with their design decisions, these apps and probably many more are unusable due to the path cleaning / redirect. |
Related: #142 |
One (quick and dirty) option would be to provide a The risk there is that it's a sharp edge that—if you don't carefully write your own path-cleaning logic—you could break your application in other ways. |
This should be fixed in #154. |
Great, thanks! |
This fixes traefik#167 and traefik#651. By default, gorilla/mux cleans URL paths such that adjacent slashes are collapsed into one single slash. This behavior is pretty common in application stacks and it is fine, but for Traefik, this can lead to incorrect URL paths forwarded to backend servers. See gorilla/mux#94 for background.
Say I have an API with a URL structure as follows:
http://example.com/library/$BOOKID/chapters
If someone hits the URL
http://example.com/library//chapters
(Fails to provide a bookID), the client will receive a 301 to a location which doesn't exist (301 -> follow -> 404)In my opinion, this behaviour should be optional, the problem is of course that
path.Clean()
is called, and (As per documentation)// 1. Replace multiple slashes with a single slash.
is performed.Most my reasoning for not wanting this behaviour is based on me not wanting my routing library to redirect my clients when I'm not explicitly asking it to.
What are others thoughts on this?
Cheers,
The text was updated successfully, but these errors were encountered: