Skip to content

Commit f53d80f

Browse files
committed
feat(storage): set auto-decompress as needed for download_stream
Fixes talkiq#988
1 parent e7fdf95 commit f53d80f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

storage/gcloud/aio/storage/storage.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,16 @@ async def _download_stream(
671671
headers = headers or {}
672672
headers.update(await self._headers())
673673

674+
# aiohttp and requests automatically decompress the body if this
675+
# argument is not passed, unless a user has explicitly disabled that
676+
# option at the session level in the case of aiohttp. We follow the
677+
# user setting by default (by passing None) and only explicitly disable
678+
# it when we know that the object is not compressed (when the
679+
# Accept-Encoding header is missing).
680+
auto_decompress = None
681+
if 'accept-encoding' not in {k.lower() for k in headers}:
682+
auto_decompress = False
683+
674684
s = AioSession(session) if session else self.session
675685

676686
if BUILD_GCLOUD_REST:
@@ -685,7 +695,7 @@ async def _download_stream(
685695
return StreamResponse(
686696
await s.get(
687697
url, headers=headers, params=params or {},
688-
timeout=timeout,
698+
timeout=timeout, auto_decompress=auto_decompress,
689699
),
690700
)
691701

0 commit comments

Comments
 (0)