Skip to content

Commit bc9e5d6

Browse files
[PR #9448/93e87c2e backport][3.10] Improve performance of fetching the content-length for web responses (#9449)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 3ea557a commit bc9e5d6

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

aiohttp/helpers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,7 @@ def charset(self) -> Optional[str]:
814814
def content_length(self) -> Optional[int]:
815815
"""The value of Content-Length HTTP header."""
816816
content_length = self._headers.get(hdrs.CONTENT_LENGTH)
817-
818-
if content_length is not None:
819-
return int(content_length)
820-
else:
821-
return None
817+
return None if content_length is None else int(content_length)
822818

823819

824820
def set_result(fut: "asyncio.Future[_T]", result: _T) -> None:

aiohttp/web_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def content_length(self) -> Optional[int]:
709709
return None
710710

711711
if hdrs.CONTENT_LENGTH in self._headers:
712-
return super().content_length
712+
return int(self._headers[hdrs.CONTENT_LENGTH])
713713

714714
if self._compressed_body is not None:
715715
# Return length of the compressed body

0 commit comments

Comments
 (0)