Skip to content

Commit

Permalink
Speed up starting compression (#9169)
Browse files Browse the repository at this point in the history
(cherry picked from commit fce4f8e)
  • Loading branch information
bdraco authored and patchback[bot] committed Sep 22, 2024
1 parent 206afde commit 657f709
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/9169.misc.rst
6 changes: 4 additions & 2 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class ContentCoding(enum.Enum):
identity = "identity"


CONTENT_CODINGS = {coding.value: coding for coding in ContentCoding}

############################################################
# HTTP Response classes
############################################################
Expand Down Expand Up @@ -427,8 +429,8 @@ async def _start_compression(self, request: "BaseRequest") -> None:
# Encoding comparisons should be case-insensitive
# https://www.rfc-editor.org/rfc/rfc9110#section-8.4.1
accept_encoding = request.headers.get(hdrs.ACCEPT_ENCODING, "").lower()
for coding in ContentCoding:
if coding.value in accept_encoding:
for value, coding in CONTENT_CODINGS.items():
if value in accept_encoding:
await self._do_start_compression(coding)
return

Expand Down

0 comments on commit 657f709

Please sign in to comment.