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

Suppress binary output on the command line. #2076

merged 1 commit into from Feb 9, 2022

Suppress binary output on the command line. #2076

merged 1 commit into from Feb 9, 2022


Copy link

@waterfountain1996 waterfountain1996 commented Feb 9, 2022

Closes #2049

Changed print_response to simply display the content length of a binary response.

get_lexer_for_response returns 'Text only' for a Content-Type: text/... response, so it will be properly displayed using rich.syntax.Syntax. Those responses which do not get a corresponding lexer are considered binary and their output is suppressed.

To make the tests pass I had to add another route to the test server that would return a binary response. Feel free to point it out if there's another way to do it.

@tomchristie tomchristie changed the title Suppress binary output on the command line (#2049) Suppress binary output on the command line. Feb 9, 2022
Copy link

Great - thanks!

Copy link

tomchristie commented Feb 9, 2022

Verified this to myself with the following...

# Nice clean virtualenv. Be explicit about which version of Python.
$ python3.9 -m venv venv

# Install from the `binary-output` branch on your repo.
$ venv/bin/pip install git+

# Also pull in the optional dependancies. Not sure I can do that with the URL style above?
$ venv/bin/pip install httpx[cli]

# Run it and check...
$ venv/bin/httpx
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Wed, 09 Feb 2022 15:33:14 GMT
Content-Type: image/jpeg
Content-Length: 35069
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Cache-Control: public, max-age=30
ETag: 1644379259564

<35069 bytes of binary data>

Copy link

Ah here we go... pypa/pip#6548

Using the following would install from your branch, and include the optional dependancies.

$ venv/bin/pip install "httpx[cli] @ git+"

@tomchristie tomchristie merged commit 4c30748 into encode:master Feb 9, 2022
5 checks passed
@tomchristie tomchristie mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

Displaying binary responses in the command line client.
2 participants