hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.58k stars 1.6k forks source link

The `size_hint` in `HttpBody` can change behavior when making GET requests with bodies #2444

Open aturon opened 3 years ago

aturon commented 3 years ago

This is a subtle one! Bodies for GET requests are ignored, unless the HttpBody::size_hint provides an exact size, in which case they are transmitted. The size_hint should not affect behavior in this way, AIUI.

I was using the general Client::request API to pass through a request that happened to be a GET with a body.

seanmonstar commented 3 years ago

Hmmm, so you have a custom type implementing size_hint that returns a possible range instead of an exact size, is that right? It does seem that if you declare there is some size hint, it should mean the body should be sent with a transfer-encoding: chunked header. Is that what you'd expect as well?

aturon commented 3 years ago

I have a custom type that, depending on the situation, may return the default size hint (unbounded), or else an exact size. My surprise was that for a GET request, the size hint affected whether the body was sent at all. I would expect that if Hyper drops the body when making GET requests, it would so so in all cases, regardless of the size hint for the body.

seanmonstar commented 3 years ago

I see, I'm starting to remember now. So, while very rare, it's legal to send a body with a GET. So hyper settled on these rules, currently:

aturon commented 3 years ago

Roger that! Thanks for the clarification. If this is intended behavior, I wonder if it could be added to documentation, in case others trip over the same issue.

jeddenlea commented 3 years ago

I think this is subtly related to https://github.com/hyperium/hyper/issues/2427