ducaale / xh

Friendly and fast tool for sending HTTP requests
MIT License
5.49k stars 96 forks source link

when add `--download` flag , xh does not requests the compressed response body #346

Closed zuisong closed 8 months ago

zuisong commented 8 months ago

When using download mode, Httpie automatically requests the compressed response body, whereas xh doesn't. This means that xh will use more traffic to download the file.

xh:

❯ xh https://httpbin.org/gzip --offline -d
GET /gzip HTTP/1.1
Accept: */*
Accept-Encoding: identity
Connection: keep-alive
Host: httpbin.org
User-Agent: xh/0.20.1

httpie:

❯ http https://httpbin.org/gzip --offline -d
GET /gzip HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: httpbin.org
User-Agent: HTTPie/3.2.2
zuisong commented 8 months ago

Having reviewed the history of the issue, I understand the reason why it happened. I am happy to implement a fix, if you have a fix in mind.

294

141

blyxxyz commented 8 months ago

We copied this behavior from HTTPie, so I was surprised to see it different in your example. Apparently with --offline it ignores --download, these are the headers it sends in online mode:

GET / HTTP/1.1
Accept: */*
Accept-Encoding: identity
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/3.2.2

I feel like requesting a compressed response might possibly be okay if --continue isn't used, but wget and aria2c don't do it automatically, so I'd first want to understand why (or to see another popular downloader that makes this decision).

wget does have an opt-in --compression option but it's marked experimental.

zuisong commented 8 months ago

Yes, httpie also doesn't automatically request compressed response body in online mode. I misread it, this issue can be closed.

Currently I solved this problem by redirecting the response body to a file, without using the --download flag.

xh your.request.url > output.file