Skip to content
Myr

Add support for brotli decoding (#5783)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add support for Brotli decoding 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. * Create the default Accept-Encoding header once * Preserve the previous delimiter behavior * Update prose in quickstart.rst

authored by Дилян Палаузов · committed by GitHub · parent 2463074 · Browse files · 4 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Seth Michael Larson <sethmichaellarson@gmail.com>

Diff stats

4 files+15 added−1 removed

  • other:+15 added−1 removed

4 files+15 added−1 removed

modified:docs/community/faq.rst+3 added
9 unmodified lines
1011Requests automatically decompresses gzip-encoded responses, and does12its best to decode response content to unicode when possible.1314When either the `brotli <https://pypi.org/project/Brotli/>`_ or `brotlicffi <https://pypi.org/project/brotlicffi/>`_15package is installed, requests also decodes Brotli-encoded responses.1617You can get direct access to the raw response (and even the socket),18if needed as well.1920
75 unmodified lines
modified:docs/user/quickstart.rst+3 added
126 unmodified lines
127 b'[{"repository":{"open_issues":0,"url":"https://github.com/...128129The ``gzip`` and ``deflate`` transfer-encodings are automatically decoded for you.130131The ``br`` transfer-encoding is automatically decoded for you if a Brotli library132like `brotli <https://pypi.org/project/brotli>`_ or `brotlicffi <https://pypi.org/project/brotli>`_ is installed.133134For example, to create an image from binary data returned by a request, you can135use the following code::136137 >>> from PIL import Image
432 unmodified lines
modified:requests/utils.py+7 added-1 removed
18 unmodified lines
19import tempfile20import warnings21import zipfile22from collections import OrderedDict23from urllib3.util import make_headers2425from .__version__ import __version__26from . import certs27# to_native_string is unused here, but imported here for backwards compatibility
13 unmodified lines
41DEFAULT_CA_BUNDLE_PATH = certs.where()4243DEFAULT_PORTS = {'http': 80, 'https': 443}4445# Ensure that ', ' is used to preserve previous delimiter behavior.46DEFAULT_ACCEPT_ENCODING = ", ".join(47 re.split(r",\s*", make_headers(accept_encoding=True)["accept-encoding"])48)495051if sys.platform == 'win32':52 # provide a proxy_bypass version on Windows without DNS lookups5354 def proxy_bypass_registry(host):
785 unmodified lines
840 :rtype: requests.structures.CaseInsensitiveDict841 """842 return CaseInsensitiveDict({843 'User-Agent': default_user_agent(),838 'Accept-Encoding': ', '.join(('gzip', 'deflate')),844 'Accept-Encoding': DEFAULT_ACCEPT_ENCODING,845 'Accept': '*/*',846 'Connection': 'keep-alive',847 })848
165 unmodified lines
modified:HISTORY.md+2 added
3 unmodified lines
4dev5---67- \[Short description of non-trivial change.\]8- Requests Brotli compression, if either the `brotli` or `brotlicffi` package9 is installed.1011**Dependencies**1213- Instead of `chardet`, use the MIT-licensed `charset_normalizer` for Python3
1714 unmodified lines