You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Displaying binary responses in the command line client. #2049
This behaviour isn't really ideal. The HTTP response is giving us enough information in the Content-Type to indicate that the response is binary, not text, so we could be doing better than this.
I'd much prefer for us to have better handling for this kind of case.
For example...
$ httpx https://cataas.com/cat
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Thu, 27 Jan 2022 10:41:25 GMT
Content-Type: image/jpeg
Content-Length: 35300
Connection: keep-alive
Access-Control-Allow-Origin: *<35300 bytes of binary data>
I've not thought through what flags we'd want for controlling this display, but it seems like an obvious improvement for us to make, and I'm sure we could do a very nice job of how it's displayed with rich.
Request on twitter for feedback couple of links to rust based examples, that might be useful for figuring out what kind of colorisation/style we'd like.
I've played around with it and I found that larger responses will take unreasonable amount of time to print (600kb takes ~20s on my machine). What would you suggest as a way around that? As for the flags, I think we could borrow the idea from curl, where it will not print the response unless output file is specified with --output flag.
I gave the hexdump style a try, and while I thought it was neat, there's not really any way I'd actually be using it in depth. At least not as my default behaviour.
I think a good enough pass at this point would simply be to do the following for binary content...
$ httpx https://cataas.com/cat
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Thu, 27 Jan 2022 10:41:25 GMT
Content-Type: image/jpeg
Content-Length: 35300
Connection: keep-alive
Access-Control-Allow-Origin: *<35300 bytes of binary data>
Activity
lovelydinosaur commentedon Jan 27, 2022
Jotting down a couple of possibly useful resources...
waterfountain1996 commentedon Feb 9, 2022
I've played around with it and I found that larger responses will take unreasonable amount of time to print (600kb takes ~20s on my machine). What would you suggest as a way around that? As for the flags, I think we could borrow the idea from curl, where it will not print the response unless output file is specified with
--outputflag.lovelydinosaur commentedon Feb 9, 2022
I gave the
hexdumpstyle a try, and while I thought it was neat, there's not really any way I'd actually be using it in depth. At least not as my default behaviour.I think a good enough pass at this point would simply be to do the following for binary content...
I think we want a switch here:
httpx/httpx/_main.py
Line 178 in a416106
To output as text for
Content-Type: text/...and output as binary otherwise.waterfountain1996 commentedon Feb 9, 2022
I'll submit a PR for this
Suppress binary output on the command line (#2049) (#2076)
Suppress binary output on the command line (encode#2049) (encode#2076)