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
merged 1 commit into from
Feb 9, 2022
Merged

Suppress binary output on the command line. #2076

merged 1 commit into from
Feb 9, 2022

Conversation

waterfountain1996
Copy link
Contributor

@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
@tomchristie
Copy link
Member

Great - thanks!

@tomchristie
Copy link
Member

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+https://github.com/waterfountain1996/httpx.git@binary-output

# 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 https://cataas.com/cat
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>

@tomchristie
Copy link
Member

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+https://github.com/waterfountain1996/httpx.git@binary-output"

@tomchristie tomchristie merged commit 4c30748 into encode:master Feb 9, 2022
@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Displaying binary responses in the command line client.
2 participants