Skip to content

Commit

Permalink
Avoid duplicate content_length fetch to prepare web response headers (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 7, 2024
1 parent cac9e13 commit dd0b6e3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ async def _prepare_headers(self) -> None:
headers[hdrs.TRANSFER_ENCODING] = "chunked"
if hdrs.CONTENT_LENGTH in headers:
del headers[hdrs.CONTENT_LENGTH]
elif self._length_check:
elif self._length_check: # Disabled for WebSockets
writer.length = self.content_length
if writer.length is None:
if version >= HttpVersion11:
Expand All @@ -420,7 +420,7 @@ async def _prepare_headers(self) -> None:
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.1-13
if hdrs.TRANSFER_ENCODING in headers:
del headers[hdrs.TRANSFER_ENCODING]
elif self.content_length != 0:
elif (writer.length if self._length_check else self.content_length) != 0:
# https://www.rfc-editor.org/rfc/rfc9110#section-8.3-5
headers.setdefault(hdrs.CONTENT_TYPE, "application/octet-stream")
headers.setdefault(hdrs.DATE, rfc822_formatted_time())
Expand Down

0 comments on commit dd0b6e3

Please sign in to comment.