diff --git a/HISTORY.md b/HISTORY.md index 0331d187f7..5100eae367 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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) ------------------- diff --git a/docs/community/faq.rst b/docs/community/faq.rst index c0177719bd..19732aedac 100644 --- a/docs/community/faq.rst +++ b/docs/community/faq.rst @@ -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. diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 0e2bcadfdc..cfcafde42b 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -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:: diff --git a/requests/utils.py b/requests/utils.py index db67938e67..325680b143 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -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 @@ -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', })