Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zuisong
Copy link
Contributor

@zuisong zuisong commented Jan 22, 2025

@zuisong zuisong force-pushed the compress-request-body branch from d7f708a to f85194a Compare January 22, 2025 10:21
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() {
Copy link
Collaborator

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.)

Copy link
Contributor Author

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. 😄

Copy link
Collaborator

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.)

Copy link
Contributor Author

@zuisong zuisong Jan 23, 2025

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.

@zuisong zuisong marked this pull request as ready for review January 22, 2025 14:25
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@zuisong zuisong force-pushed the compress-request-body branch from e64e14f to 1ec0267 Compare January 23, 2025 01:19
@zuisong zuisong marked this pull request as draft January 23, 2025 05:31
@zuisong zuisong marked this pull request as ready for review January 23, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants