-
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
Unusual path parameter values make mux to choose incorrect handler #308
Comments
This may be related to #300 |
Can you check if the latest version fixes the problem for you? |
Seems not to fix that. I having cleared out the previous package traces from |
Normal paths from the tests in the OP:
Paths noted as "unexpected" in the OP:
I don't see the bug on the latest HEAD (65ec724). |
Can you provide a log of the full request sent by Postman? I imagine it must print it somewhere |
Very odd. Can you just have the handler log directly, hit it with Postman,
and see what the server itself says?
I suspect Postman has buggy output given that curl has no issue.
…On Wed, Nov 29, 2017 at 11:23 PM Sergey Seleznev ***@***.***> wrote:
I have this one, but it is more like request-response details:
[image: image]
<https://user-images.githubusercontent.com/18219010/33418740-02848548-d5b0-11e7-96ce-f7e26f984251.png>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#308 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABIcDXBnn1Vgg23dpgr0X5A4L9U4OZnks5s7lgGgaJpZM4QFqAe>
.
|
@elithrar it outputs the same that Postman receives.
I would blame Postman, but it's actually getting expected response calling a sample ASP.NET Core WebAPI server containing just a couple lines of custom code:
So I guess it's some request specifics of Postman (that could come from other client as well) that gets mux to mix up the handlers. |
Here's a reproducer in Go, using the server code from the post above:
The first one results in |
With some further testing and debugging I narrowed the problem down to here: https://github.com/gorilla/mux/blob/master/mux.go#L122 When the client receives the redirect, it retries the request with a |
It behaves correctly when using |
@kisielk Correct, a 308 allows a retry w/ the same method, and a 301/302 must change to a GET on the subsequent (re-directed) request. 308 isn't as widely supported on all clients, so this is a little tricky. This isn't so much "broken" as implicit. I also loathe "more dials" to configure things. Perhaps default to 308 (newer) and allow a hook to modify that if need be? |
I'm inclined to leave it as it is. At least 301 is understood by all clients, and nothing bad will happen. If you have a client that's making POST requests to a URL that results in a redirect, and they turn into GETs then you could either: a) Fix your request URL If we switch it to 308, the only advantage is that you don't need to do a) or b), but the potential consequence is that some clients won't understand the status code at all, and it could break some existing uses. |
SGTM.
We should add this to the documentation for StrictSlash to make the
behavior clear to users.
…On Fri, Dec 1, 2017 at 3:46 PM Kamil Kisiel ***@***.***> wrote:
I'm inclined to leave it as it is. At least 301 is understood by all
clients, and nothing bad will happen. If you have a client that's making
POST requests to a URL that results in a redirect, and they turn into GETs
then you could either:
a) Fix your request URL
b) Configure your client to try the redirected URL with POSTs instead of
switching to GETs (it seems curl already does this).
If we switch it to 308, the only advantage is that you don't need to do a)
or b), but the potential consequence is that some clients won't understand
the status code at all, and it could break some existing uses.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#308 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABIcPLGjg8RrMNpv_pjgGa0T_IiG4kBks5s8I_bgaJpZM4QFqAe>
.
|
* StrictSlash enabled routes return a 301 to the client * As per the HTTP standards, non-idempotent methods, such as POST or PUT, will be followed with a GET by the client * Users should use middleware if they wish to change this behaviour to return a HTTP 308.
See PR #321 Closing this out, but let me know if there are outstanding concerns. |
* [docs] Note StrictSlash re-direct behaviour #308 * StrictSlash enabled routes return a 301 to the client * As per the HTTP standards, non-idempotent methods, such as POST or PUT, will be followed with a GET by the client * Users should use middleware if they wish to change this behaviour to return a HTTP 308. * Update description of StrictSlash
Hi!
I would like to define a number of handlers, that have:
Here's a simplified example:
It seems that
mux
tends to ignore methods and select improper handler in some specific cases:http://localhost:8080/files/file.txt
=>[GET] file.txt
(OK)http://localhost:8080/files/file.txt
=>[POST] file.txt
(OK)http://localhost:8080/files/path/to/file.txt
=>[GET] path/to/file.txt
(OK)http://localhost:8080/files/path/to/file.txt
=>[POST] path/to/file.txt
(OK)http://localhost:8080/files/path/to//file.txt
=>[GET] path/to/file.txt
(OK)http://localhost:8080/files/path/to//file.txt
=>[GET] path/to/file.txt
(unexpected)http://localhost:8080/files/path/to/./file.txt
=>[GET] path/to/file.txt
(OK)http://localhost:8080/files/path/to/./file.txt
=>[GET] path/to/file.txt
(unexpected)http://localhost:8080/files/path/to/../file.txt
=>[GET] path/file.txt
(OK)http://localhost:8080/files/path/to/../file.txt
=>[GET] path/file.txt
(unexpected)Handler declaration order doesn't change the tests results mentioned.
The text was updated successfully, but these errors were encountered: