Skip to content

Commit

Permalink
Add auto_decompress parameter to ClientSession.request()
Browse files Browse the repository at this point in the history
This optional parameter overrides `ClientSession.auto_decompress` on a
per-request basis.

Implements changes proposed in aio-libs#3751
  • Loading branch information
Daste745 committed Oct 27, 2022
1 parent 12f56d7 commit 1f6e779
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/3751.feature
@@ -0,0 +1 @@
Added ``auto_decompress`` parameter to ``ClientSession.request`` to override ``ClientSession._auto_decompress``. -- by :user:`Daste745`
6 changes: 5 additions & 1 deletion aiohttp/client.py
Expand Up @@ -351,6 +351,7 @@ async def _request(
proxy_headers: Optional[LooseHeaders] = None,
trace_request_ctx: Optional[SimpleNamespace] = None,
read_bufsize: Optional[int] = None,
auto_decompress: Optional[bool] = None,
) -> ClientResponse:

# NOTE: timeout clamps existing connect and read timeouts. We cannot
Expand Down Expand Up @@ -411,6 +412,9 @@ async def _request(
if read_bufsize is None:
read_bufsize = self._read_bufsize

if auto_decompress is None:
auto_decompress = self._auto_decompress

traces = [
Trace(
self,
Expand Down Expand Up @@ -512,7 +516,7 @@ async def _request(
timer=timer,
skip_payload=method.upper() == "HEAD",
read_until_eof=read_until_eof,
auto_decompress=self._auto_decompress,
auto_decompress=auto_decompress,
read_timeout=real_timeout.sock_read,
read_bufsize=read_bufsize,
timeout_ceil_threshold=self._connector._timeout_ceil_threshold,
Expand Down
10 changes: 7 additions & 3 deletions docs/client_reference.rst
Expand Up @@ -164,8 +164,7 @@ The client session supports the context manager protocol for self closing.
connection pool between sessions without sharing session state:
cookies etc.

:param bool auto_decompress: Automatically decompress response body,
``True`` by default
:param bool auto_decompress: Automatically decompress response body (``True`` by default).

.. versionadded:: 2.3

Expand Down Expand Up @@ -338,7 +337,8 @@ The client session supports the context manager protocol for self closing.
proxy=None, proxy_auth=None,\
timeout=sentinel, ssl=None, \
verify_ssl=None, fingerprint=None, \
ssl_context=None, proxy_headers=None)
ssl_context=None, proxy_headers=None, \
auto_decompress=None)
:async-with:
:coroutine:
:noindexentry:
Expand Down Expand Up @@ -510,6 +510,10 @@ The client session supports the context manager protocol for self closing.

.. versionadded:: 3.0

:param bool auto_decompress: Automatically decompress response body.
Overrides :attr:`ClientSession.auto_decompress`.
May be used to disable auto decompression on a per-request basis.

:return ClientResponse: a :class:`client response <ClientResponse>`
object.

Expand Down

0 comments on commit 1f6e779

Please sign in to comment.