-
-
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
Automatic Gzip Decoding. #61
Automatic Gzip Decoding. #61
Conversation
tests/client.rs
Outdated
HTTP/1.1 200 OK\r\n\ | ||
Server: test-accept\r\n\ | ||
Content-Encoding: gzip\r\n\ | ||
Content-Length: 0\r\n\ |
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.
You're telling reqwest that the length of the response body is 0, and hyper will enforce this. After reading the headers, when trying to read the body from hyper, it will report that the body is empty.
- So, the easy fix is to change this to the length of the body (in this case, 105) (a wonderful example of how compression actually explodes small values, 12 -> 105!).
- I'm wondering if this specific case should also be fix. If there is no body, should the read just return
Ok(0)
? Or should point out that decoding an empty body doesn't work, and so the response is malformed? I'm probably leaning towards don't error (however, awarn!
log may be appropriate.)
28fc646
to
7a55ec3
Compare
@seanmonstar Oh, thanks for pointing that out. Fixed now, tests are passing. I can do a little digging to see what other libs do when trying to gzip decode a non-gzipped body if you'd like. |
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.
We probably want an option to allow someone to enable or disable this behavior. Either on the Client
, or on an individual request. Considering that all the other configuration is on the Client
, probably should be there.
let mut client = Client::new();
client.gzip(false);
src/client.rs
Outdated
@@ -317,27 +319,37 @@ impl fmt::Debug for RequestBuilder { | |||
} | |||
|
|||
/// A Response to a submitted `Request`. | |||
#[derive(Debug)] |
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.
I'd actually keep the previous Debug
version, it provides just the information that someone would want when writing logs.
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.
The old version of debug has been implemented on Decoder
since the Decoder::Plaintext
variant is now wrapping the hyper request. So deriving debug here makes sense since all Request
is doing is wrapping a Decoder
now. See changes on line 430
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.
Hm, what I meant was that the debug output probably doesn't need to leak the details of what kind of decoder it is using.
println!("res = {:?}", res);
Ideally that prints something like:
res = Response { status: Ok, headers: { ... }, version: Http11, }
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.
Ah, gotcha. Sounds good by me, I'll make the change.
7a55ec3
to
0d153cb
Compare
On the topic of making automatically ungzipping configurable, I see two places where the config option can go: If its put on If we put the property on Which would you prefer? |
I'd say put it in the On a separate note, I've noticed that this fails on Windows msys (thanks AppVeyor!). It seems like it cannot be fixed in flate2 crate, based on rust-lang/flate2-rs#42. We might have to use either https://github.com/sile/libflate or https://github.com/PistonDevelopers/inflate |
I don't mind swapping in one of those libs. Seems fairly effortless to do so. The alternative would be to do what @alexcrichton suggested in his comment. I'd prefer to defer to you on this decision. |
} | ||
if let Some(content_length) = res.headers.get::<ContentLength>() { | ||
if content_length.0 == 0 { | ||
warn!("GZipped response with content-length of 0"); |
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.
From outdated change:
I'm wondering if this specific case should also be fix. If there is no body, should the read just return Ok(0)? Or should point out that decoding an empty body doesn't work, and so the response is malformed? I'm probably leaning towards don't error (however, a warn! log may be appropriate.)
This look good? Error message could probably be improved.
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.
This looks good to me!
Yea, I don't think requiring that people install MSVC is something I want to do. If they have Rust working in mingw, then reqwest should hopefully work fine for them. One of the main goals of reqwest is to be extremely easy to setup and do the Right Thing. |
@seanmonstar Sounds good, I'll swap out flate2 for one of the alternatives listed above and ping you whe its ready for review again. |
@seanmonstar Replaced flate2-rs with libflate and updated the debug impl as you requested. Let me know if you'd like any other changes or if all looks good so I can squash the commits before merging. |
Looks perfect, thanks!
…On Sat, Feb 25, 2017, 11:36 PM Jason Schein ***@***.***> wrote:
@seanmonstar <https://github.com/seanmonstar> Replaced flate2-rs with
libflate and updated the debug impl as you requested. Let me know if you'd
like any other changes or if all looks good so I can squash the commits
before merging.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADJF9d0oBpLTwggyf6yihlOMzDum3E5ks5rgStngaJpZM4MFT0g>
.
|
7e78370
to
44a016f
Compare
44a016f
to
ab5e477
Compare
@seanmonstar Squashed and ready. |
Thanks so much @echochamber for keeping up on this, this will be a nice feature to release! |
@seanmonstar Thanks for the regular help and feedback along the way. I Doubt I would have actually been able to get this working without it! |
Hey, got a chance to work on this again. Fixed all the merge conflicts and verified its working by testing it manually same as before.
Old PR: #25
Resolves Issue 3 #3
I'm having some difficulty using the server macro to create the response. Basically I know I'm not appending the gzipped bytes after the headers correctly but can't figure out how to do it correctly. Been banging my head against the problem long enough I thought I'd ask for help.
I know its failing on this line when unwrapping the GzDecoder (likely because the content wasn't valid gzipped bytes because I am appending them incorrectly).
decoder: GzDecoder::new(res).unwrap()
Hopefully its an easy fix.