Skip to content

Commit 429ec17

Browse files
[PR #9575/951def15 backport][3.11] Switch to using URL.host_port_subcomponent in yarl for the client host header (#9578)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 9cd73e3 commit 429ec17

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

aiohttp/client_reqrep.py

+2-21
Original file line numberDiff line numberDiff line change
@@ -433,30 +433,11 @@ def update_headers(self, headers: Optional[LooseHeaders]) -> None:
433433
self.headers: CIMultiDict[str] = CIMultiDict()
434434

435435
# Build the host header
436-
host = self.url.host_subcomponent
436+
host = self.url.host_port_subcomponent
437437

438-
# host_subcomponent is None when the URL is a relative URL.
438+
# host_port_subcomponent is None when the URL is a relative URL.
439439
# but we know we do not have a relative URL here.
440440
assert host is not None
441-
442-
if host[-1] == ".":
443-
# Remove all trailing dots from the netloc as while
444-
# they are valid FQDNs in DNS, TLS validation fails.
445-
# See https://github.com/aio-libs/aiohttp/issues/3636.
446-
# To avoid string manipulation we only call rstrip if
447-
# the last character is a dot.
448-
host = host.rstrip(".")
449-
450-
# If explicit port is not None, it means that the port was
451-
# explicitly specified in the URL. In this case we check
452-
# if its not the default port for the scheme and add it to
453-
# the host header. We check explicit_port first because
454-
# yarl caches explicit_port and its likely to already be
455-
# in the cache and non-default port URLs are far less common.
456-
explicit_port = self.url.explicit_port
457-
if explicit_port is not None and not self.url.is_default_port():
458-
host = f"{host}:{explicit_port}"
459-
460441
self.headers[hdrs.HOST] = host
461442

462443
if not headers:

0 commit comments

Comments
 (0)