Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of fetching the content-length for web responses #9448

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,9 @@ 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:
if content_length is None:
return None
return int(content_length)
bdraco marked this conversation as resolved.
Show resolved Hide resolved


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