Skip to content

Commit

Permalink
extract chunked detection into AIOHTTPSession._chunked()
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller committed Mar 4, 2024
1 parent d362bfa commit ef46b6a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions aiobotocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def _setup_proxy_ssl_context(self, proxy_url):
except (OSError, LocationParseError) as e:
raise InvalidProxiesConfigError(error=e)

def _chunked(self, headers):
transfer_encoding = headers.get('Transfer-Encoding', '')
if chunked := transfer_encoding.lower() == 'chunked':
# aiohttp wants chunking as a param, and not a header
del headers['Transfer-Encoding']
return chunked

def _create_connector(self, proxy_url):
ssl_context = None
if bool(self._verify):
Expand Down Expand Up @@ -208,12 +215,6 @@ async def send(self, request):
# https://github.com/boto/botocore/issues/1255
headers_['Accept-Encoding'] = 'identity'

chunked = None
if headers_.get('Transfer-Encoding', '').lower() == 'chunked':
# aiohttp wants chunking as a param, and not a header
headers_.pop('Transfer-Encoding', '')
chunked = True

if isinstance(data, io.IOBase):
data = _IOBaseWrapper(data)

Expand All @@ -222,7 +223,7 @@ async def send(self, request):
response = await session.request(
request.method,
url=url,
chunked=chunked,
chunked=self._chunked(headers_),
headers=headers_,
data=data,
proxy=proxy_url,
Expand Down

0 comments on commit ef46b6a

Please sign in to comment.