diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index d536c0a1ca4..c063c56314e 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -3,6 +3,7 @@ import contextlib import functools import io +import itertools import re import sys import traceback @@ -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: "*/*", @@ -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)