Skip to content

Commit

Permalink
Improve performance of fetching the content-length for web responses (#…
Browse files Browse the repository at this point in the history
…9448)

Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
bdraco and Dreamsorcerer authored Oct 10, 2024
1 parent 4561c39 commit 93e87c2
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 @@ -747,11 +747,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 @@ -646,7 +646,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 93e87c2

Please sign in to comment.