Skip to content

Commit

Permalink
Ensure empty body responses never generate an invalid chunked response
Browse files Browse the repository at this point in the history
aiohttp < 3.9.0 will generate an invalid chunked response
if we reached the streaming handler for 204, 304, and a few
other cases. Additionally its inefficient to send a StreamResponse
when a normal Response will do.

When we upgrade to 3.9.0 we should replace this check with the aiohttp
must_be_empty_body helper:
https://github.com/aio-libs/aiohttp/blob/8ae650bee4add9f131d49b96a0a150311ea58cd1/aiohttp/helpers.py#L1061
  • Loading branch information
bdraco committed Nov 14, 2023
1 parent c475040 commit 9cc29f8
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions supervisor/api/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,15 @@ async def _handle_request(
# Simple request
code = result.status
if (
(
hdrs.CONTENT_LENGTH in result.headers
and int(result.headers.get(hdrs.CONTENT_LENGTH, 0)) < 4_194_000
)
# empty body responses should not be streamed,
# otherwise aiohttp < 3.9.0 may generate
# an invalid "0\r\n\r\n" chunk instead of an empty response.
#
# The below is from
# https://github.com/aio-libs/aiohttp/blob/8ae650bee4add9f131d49b96a0a150311ea58cd1/aiohttp/helpers.py#L1061
or must_be_empty_body(request.method, code)
must_be_empty_body(request.method, code)
or hdrs.CONTENT_LENGTH in result.headers
and int(result.headers.get(hdrs.CONTENT_LENGTH, 0)) < 4_194_000
):
# Return Response
body = await result.read()
Expand Down

0 comments on commit 9cc29f8

Please sign in to comment.