Skip to content

Commit

Permalink
[PR #9448/93e87c2e backport][3.10] Improve performance of fetching th…
Browse files Browse the repository at this point in the history
…e content-length for web responses (#9449)

Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
patchback[bot] and bdraco authored Oct 10, 2024
1 parent 3ea557a commit bc9e5d6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,7 @@ def charset(self) -> Optional[str]:
def content_length(self) -> Optional[int]:
"""The value of Content-Length HTTP header."""
content_length = self._headers.get(hdrs.CONTENT_LENGTH)

if content_length is not None:
return int(content_length)
else:
return None
return None if content_length is None else int(content_length)


def set_result(fut: "asyncio.Future[_T]", result: _T) -> None:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def content_length(self) -> Optional[int]:
return None

if hdrs.CONTENT_LENGTH in self._headers:
return super().content_length
return int(self._headers[hdrs.CONTENT_LENGTH])

if self._compressed_body is not None:
# Return length of the compressed body
Expand Down

0 comments on commit bc9e5d6

Please sign in to comment.