-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
"GET" route matches both GET & POST requests? #447
Comments
Hrm, that's really unfortunate. Do you think you could put together a PR with a test case in our integration tests to demonstrate this error? |
From https://stackoverflow.com/questions/45901389/why-golang-grpc-gateways-get-route-matches-post-request By spec, it is allowed to encode GET request into a POST method with Content-Type: application/x-www-url-encoded. See https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/mux.go#L254 So the request routing table in grpc-gateway tries to fallback from POST method to GET when the Content-Type of your request is application/x-www-url-encoded. From https://groups.google.com/d/msg/grpc-io/Xqx80hG0D44/1gwmwBcnNScJ
Another one example:
curl -X POST http://127.0.0.1:8040/api/v1/user/127 -d '{}' curl -X POST http://127.0.0.1:8040/api/v1/user/127 The question is - how to disable this behaviour? This is weird that any "Content-Type" causes expected error 501 NOT_IMPLEMENTED except "application/x-www-url-encoded". |
@UladzimirTrehubenka thanks for that incredibly interesting summary of the issue, but I'm not sure I understand what needs to be done. Should we implement an option in the generator/mix to disable this behaviour? |
Separate option would be good enough. I just wondering do we have some workaround right now? |
Not as far as I know. So would this be a runtime option or a generator option? |
I guess generator option, BTW could we have some global option in proto to disable "application/x-www-url-encoded" for all POST calls? Probably if we will have a lot of POST calls it will be not so useful to disable "application/x-www-url-encoded" for each call explicitly? |
Hm, I made a simple string search for |
Thanks for pointing that out, seeing as it is tied to the mux I think we can make this a runtime option. |
Would you be interested in submitting a patch for this @UladzimirTrehubenka? |
@yugui could you please provide some comments? |
I think it should be fairly straightforward, add an option that sets a variable, then check the value of the variable before handling the fallback. |
Any progress here? |
Unfortunately none of the maintainers are able to dedicate any work to this right now, what can I do to help you get a pull request fix for this? |
Don't follow - where we need to set the option? |
Something like this: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/mux.go#L99. Except |
As I understand you propose to add another one ServeMuxOption and set the override behaviour at runtime? |
Yes, it seems suitable as a runtime option, not something that's specific to your API. Do you disagree? |
I like this solution, so I try to create PR for fix this. |
The PR has been added. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The issue was fixed. |
I found a "get" route will match both HTTP GET and HTTP POST requests. For example:
It matches both
curl -v -X GET -k https://127.0.0.1/api/v1/aaa
andcurl -v -X POST -k https://127.0.0.1/api/v1/aaa
.I was wondering if it's possible to strictly match all routes including methods?
The text was updated successfully, but these errors were encountered: