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

[PR #9477/ce33b695 backport][3.10] Speed up matching the host header when updating client headers #9478

Merged
Changes from all 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: 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
Loading