-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Reqwest doesn't protect agains incorrect usage of HTTP verbs #2526
Comments
I dont think this is a good idea.
It SHOULD NOT. Every http verb (even custom ones) can contain a body. And it is acutally used like in opensearch or elastic where queries can very fast reach the "soft limit" of 255 bytes for the url when you are using query parameters. It is not recommended because proxies may cache GET results and ignore the body or discard the body completely because GET is Idempotent by the definition. But in cases like with elastic where you can guarantee that the service and proxies (mostly none) can handle it there is no reason to not allow it.
I would not consider elastic etc. extremely rare cases as they are most established and widely used search services. TLDR: |
Maybe a opt-in feature flag would be reasonable but IMO this is useless maintenance of code. |
So this is not ideal if client does something by default that spec says it shouldn't be doing, right? I'm talking about defaults, having some backdoor for such cases can be allowed. But the default should listen to |
The spec clearly stats that it can be done EVERY http method can contain a Body Even GET so to be able to do that I would Need to enable a Feature? And if js disables this I think thats a reason we should not do the same. |
C#: Java: Go: ... and others I won't list now All major libraries in all major languages protect against such usages. Therer are backdoor hatches that allow this for rare cases when it is required, but the overall consensus is that the lib API should protect against this by default. |
My question When You Need this do You Need an external Library to handle this? Because Java does not have Feature Flags so it is impossible to send reqeusts to elastic with the std Client? Again These are all Bugs because it is allowed and if you know the routes, middlemans and Service you absolutly can send a GET with a Body without a problem. |
But the question it why implementing this restriction? If a user makes a get and the Service doesnt Support it he will get an error code And again the following Services REQUIRE sending a Body with GET
|
it is possible, you just need to be more explicit about this, i.e. use I never proposed to ban such cases entirely - and I'm sorry if I made such an impression - I'm just talking about defaults. I had already several bugs in our existing codebase with erroneous |
IMO When you have something Like this You Need more Tests Not an error. If it is still possible it is ok but I am still against it. But I am not a maintainer |
That's actually what I was most curious about: if people commonly make the mistake. We could make it harder at compile time, by introducing a But we have to consider if the increase to surface area complexity of the API is worth it. I'm undecided. |
@seanmonstar yes, I understand the tradeoffs, this is why I stated this in my original post: if you are overall in support of this I can try working on a more detailed design or even an impl, but if you aren't comfortable with the change I will know about it before I am heavily invested into this. |
Most of existing HTTP client implementation have safeguards against incorrect usage of HTTP verbs. For example, following JS code:
Raises an error:
TypeError: Request with GET/HEAD method cannot have body.
Most of clients in other languages do this as well.
It makes sense if following Rust code was also producing an error:
The specification is pretty much against allowing such code to be executed:
While it might be valuable to keep a backdoor for extremely rare cases where server violates HTTP semantic and requires such requests, I think it is worth making this an error by-default.
I can work on an implementation if overall idea is supported by crate maintainers.
The text was updated successfully, but these errors were encountered: