diff --git a/google/auth/transport/aiohttp_requests.py b/google/auth/transport/aiohttp_requests.py index 29ecb3ad5..3d85e2b50 100644 --- a/google/auth/transport/aiohttp_requests.py +++ b/google/auth/transport/aiohttp_requests.py @@ -18,10 +18,10 @@ import asyncio import functools -import zlib import aiohttp import six +import urllib3 from google.auth import exceptions from google.auth import transport @@ -35,12 +35,12 @@ class _CombinedResponse(transport.Response): """ In order to more closely resemble the `requests` interface, where a raw - and deflated content could be accessed at once, this class lazily reads the + and deflated content could be accessed at once, this class lazily reads the stream in `transport.Response` so both return forms can be used. - The gzip and deflate transfer-encodings are automatically decoded for you + The gzip and deflate transfer-encodings are automatically decoded for you because the default parameter for autodecompress into the ClientSession is set - to False, and therefore we add this class to act as a wrapper for a user to be + to False, and therefore we add this class to act as a wrapper for a user to be able to access both the raw and decoded response bodies - mirroring the sync implementation. """ @@ -50,7 +50,7 @@ def __init__(self, response): self._raw_content = None def _is_compressed(self): - headers = self._client_response.headers + headers = self._response.headers return "Content-Encoding" in headers and ( headers["Content-Encoding"] == "gzip" or headers["Content-Encoding"] == "deflate" @@ -76,10 +76,13 @@ async def raw_content(self): async def content(self): if self._raw_content is None: self._raw_content = await self._response.content.read() - if self._is_compressed: - d = zlib.decompressobj(zlib.MAX_WBITS | 32) - decompressed = d.decompress(self._raw_content) + if self._is_compressed(): + decoder = urllib3.response.MultiDecoder( + self._response.headers["Content-Encoding"] + ) + decompressed = decoder.decompress(self._raw_content) return decompressed + return self._raw_content