Skip to content

Commit

Permalink
[PR #9477/ce33b695 backport][3.10] Speed up matching the host header …
Browse files Browse the repository at this point in the history
…when updating client headers (#9478)

Co-authored-by: J. Nick Koston <[email protected]>
  • Loading branch information
patchback[bot] and bdraco authored Oct 13, 2024
1 parent bbf7da3 commit c8bfde8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import contextlib
import functools
import io
import itertools
import re
import sys
import traceback
Expand Down Expand Up @@ -244,6 +245,9 @@ class ClientRequest:
}
POST_METHODS = {hdrs.METH_PATCH, hdrs.METH_POST, hdrs.METH_PUT}
ALL_METHODS = GET_METHODS.union(POST_METHODS).union({hdrs.METH_DELETE})
_HOST_STRINGS = frozenset(
map("".join, itertools.product(*zip("host".upper(), "host".lower())))
)

DEFAULT_HEADERS = {
hdrs.ACCEPT: "*/*",
Expand Down Expand Up @@ -470,7 +474,7 @@ def update_headers(self, headers: Optional[LooseHeaders]) -> None:

for key, value in headers: # type: ignore[misc]
# A special case for Host header
if key.lower() == "host":
if key in self._HOST_STRINGS:
self.headers[key] = value
else:
self.headers.add(key, value)
Expand Down

0 comments on commit c8bfde8

Please sign in to comment.