Skip to content

Commit

Permalink
Add support for brotli decoding
Browse files Browse the repository at this point in the history
When the brotli or brotlicffi packages are installed,
urllib3.util.make_headers() inserts ',br' in the Accept-Encoding header
and decodes br from the answers.
  • Loading branch information
dilyanpalauzov committed Mar 29, 2021
1 parent 2c2138e commit e44b721
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dev
---

- \[Short description of non-trivial change.\]
- Requests brotli compression, if either the `brotli` or `brotlicffi` package
is installed.

2.25.1 (2020-12-16)
-------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/community/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Encoded Data?
Requests automatically decompresses gzip-encoded responses, and does
its best to decode response content to unicode when possible.

When either the brotli or brotlicffi package is installed, requests
also decodes brotli-encoded responses.

You can get direct access to the raw response (and even the socket),
if needed as well.

Expand Down
3 changes: 3 additions & 0 deletions docs/user/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ You can also access the response body as bytes, for non-text requests::

The ``gzip`` and ``deflate`` transfer-encodings are automatically decoded for you.

The ``br`` transfer-encoding is automatically decoded, if either the brotli or
brotlicffi package is installed.

For example, to create an image from binary data returned by a request, you can
use the following code::

Expand Down
3 changes: 2 additions & 1 deletion requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import warnings
import zipfile
from collections import OrderedDict
from urllib3.util import make_headers

from .__version__ import __version__
from . import certs
Expand Down Expand Up @@ -820,7 +821,7 @@ def default_headers():
"""
return CaseInsensitiveDict({
'User-Agent': default_user_agent(),
'Accept-Encoding': ', '.join(('gzip', 'deflate')),
'Accept-Encoding': make_headers(accept_encoding=True)["accept-encoding"],
'Accept': '*/*',
'Connection': 'keep-alive',
})
Expand Down

0 comments on commit e44b721

Please sign in to comment.