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

Fix building the URL in BaseRequest when the host contains a port or IPv6 address #9309

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@
- overridden value by .clone(host=new_host) call.
- HOST HTTP header
- socket.getfqdn() value

For example, 'example.com' or 'localhost:8080'.

For historical reasons, the port number may be included.
"""
host = self._message.headers.get(hdrs.HOST)
if host is not None:
Expand All @@ -444,7 +448,12 @@

@reify
def url(self) -> URL:
url = URL.build(scheme=self.scheme, host=self.host)
"""The full URL of the request."""
host, has_port, port = self.host.partition(":")
bdraco marked this conversation as resolved.
Show resolved Hide resolved
if has_port:
url = URL.build(scheme=self.scheme, host=host, port=port)

Check warning on line 454 in aiohttp/web_request.py

View check run for this annotation

Codecov / codecov/patch

aiohttp/web_request.py#L454

Added line #L454 was not covered by tests
bdraco marked this conversation as resolved.
Show resolved Hide resolved
else:
url = URL.build(scheme=self.scheme, host=host)
return url.join(self._rel_url)

@reify
Expand Down
Loading