-
Notifications
You must be signed in to change notification settings - Fork 101
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
support compress request body #403
base: master
Are you sure you want to change the base?
Conversation
d7f708a
to
f85194a
Compare
src/main.rs
Outdated
if args.compress >= 1 && request.headers().get(CONTENT_ENCODING).is_none() { | ||
let mut compressed = false; | ||
if let Some(body) = request.body_mut() { | ||
if let Some(body_bytes) = body.as_bytes() { |
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.
Can we make this work for streaming requests as well (i.e. xh -x : @file.txt
)? In that case it might be best to just compress unconditionally even with a single -x
so that we don't have to buffer it.
(HTTPie does buffer the whole file in this case.)
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 think it's possible; the latest commit supports this. 😄
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.
Awesome, that gets us the same behavior as HTTPie. But we might want to diverge from HTTPie by streaming the body in this case instead of buffering it, so that it's possible to upload files that don't fit in RAM. That should be possible with ReqwestBody::new
.
(I also suggested this in httpie/cli#1613 so we could wait to see what they think.)
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 can directly compress the stream without buffering it , which would make it different from httpie's implementation.
Should we do it this way in this PR?
[update] The into_reader()
method of reqwest#Body
is pub(crate)
. We cannot access it. Currently, it is not possible to achieve our goal.
e64e14f
to
1ec0267
Compare
implements https://httpie.io/docs/cli/compressed-request-body