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
fix: Body's reader is now optional; may be checked for emptiness #14
Conversation
This looks like a reasonable change to me, though I cannot comment if there is ever a use case where somebody wants to send a non-empty body, but with zero length. I assume there is, since
Http before this change only allowed 2 and 3, after this change only allows 1. and 3. Is that acceptable? |
Actually, 2 is still permitted if you create a body with an empty string or array. It's only considered empty if you create a body with |
@mmstick Huh, it reads as if this code is eating that case: https://github.com/http-rs/http-client/pull/14/files#diff-5f9a78c705c3d5bd9ffa2d115d3085acR46 i.e. if your string is empty, it will be turned into |
The bug we're trying to fix sounds like: "if we don't have a body, actually don't send a body". My understanding of the use cases we need to support:
I just merged #15 which allows discerning between the second and third cases. The current patch should probably be rebased on master so we can cover all cases. Is this all accurate? |
407adc0
to
0b27d1e
Compare
@SirVer That would be a negative, because the impl for |
0b27d1e
to
5b6cadf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Thanks for the explanations!
http-rs/surf#117 (comment) might need to be applied, but we can do that in a follow-up patch. Overall this looks great, and we should merge! |
SUMMARY: Fixes the integration issue with isahc, whereby a `isahc::Body` created from `isahc::Body::reader`has a length of `None`, which signals to `isahc::Client` to send a body with an unknown length. A length of `None` is interpreted as being unknown, and therefore a body is sent with every request. This causes a 501 error on servers which do not permit a body in the request, such as GET requests to Cloudflare CDNs. CHANGES: * Changed `http_client::Body`'s `reader` field to being optional * Added a `http_client::Body::is_empty` method to check for emptiness * On creating a new request for `isahc::Client`: - Create a `isahc::Body::empty` if `http_client::Body` is empty - Create a `isahc::Body::reader` if otherwise not empty
5b6cadf
to
851baf3
Compare
Change made |
SUMMARY:
Fixes the integration issue with isahc, whereby a
isahc::Body
created fromisahc::Body::reader
has a length ofNone
, which signals toisahc::Client
to send a body with an unknown length. A length of
None
is interpreted asbeing unknown, and therefore a body is sent with every request. This causes a
501 error on servers which do not permit a body in the request, such as GET
requests to Cloudflare CDNs.
CHANGES:
http_client::Body
'sreader
field to being optionalhttp_client::Body::is_empty
method to check for emptinessisahc::Client
:isahc::Body::empty
ifhttp_client::Body
is emptyisahc::Body::reader
if otherwise not empty