Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions google/auth/transport/aiohttp_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
"""
Expand All @@ -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"
Expand All @@ -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


Expand Down