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

Add support for host_port_subcomponent #1375

Merged
merged 7 commits into from
Oct 22, 2024
Merged

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Oct 22, 2024

Adds a new property host_port_subcomponent with the goal of replacing

Copy link

codspeed-hq bot commented Oct 22, 2024

CodSpeed Performance Report

Merging #1375 will not alter performance

Comparing host_port_subcompoment (eed5981) with master (081f1ba)

Summary

✅ 83 untouched benchmarks

🆕 1 new benchmarks

Benchmarks breakdown

Benchmark master host_port_subcompoment Change
🆕 test_url_host_port_subcomponent N/A 464.7 µs N/A

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.05%. Comparing base (5143823) to head (eed5981).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1375      +/-   ##
==========================================
+ Coverage   96.02%   96.05%   +0.02%     
==========================================
  Files          31       31              
  Lines        5713     5748      +35     
  Branches      356      360       +4     
==========================================
+ Hits         5486     5521      +35     
  Misses        201      201              
  Partials       26       26              
Flag Coverage Δ
CI-GHA 96.05% <100.00%> (+0.02%) ⬆️
MyPy 45.97% <80.00%> (+0.21%) ⬆️
OS-Linux 99.55% <100.00%> (+<0.01%) ⬆️
OS-Windows 99.61% <100.00%> (+<0.01%) ⬆️
OS-macOS 99.29% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.10.15 99.51% <100.00%> (+<0.01%) ⬆️
Py-3.11.10 99.51% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.12.7 99.51% <100.00%> (+<0.01%) ⬆️
Py-3.13.0 99.51% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 99.23% <100.00%> (+<0.01%) ⬆️
Py-3.9.20 99.46% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 99.52% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.17 99.55% <100.00%> (+<0.01%) ⬆️
VM-macos-latest 99.29% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 99.55% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 99.61% <100.00%> (+<0.01%) ⬆️
pytest 99.55% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 22, 2024
@bdraco
Copy link
Member Author

bdraco commented Oct 22, 2024

Need to modify aiohttp to use this and run tests against it

@bdraco
Copy link
Member Author

bdraco commented Oct 22, 2024

all tests pass downstream with this change

diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py
index 57df4b016..ca40c19e5 100644
--- a/aiohttp/client_reqrep.py
+++ b/aiohttp/client_reqrep.py
@@ -433,30 +433,10 @@ class ClientRequest:
         self.headers: CIMultiDict[str] = CIMultiDict()
 
         # Build the host header
-        host = self.url.host_subcomponent
-
+        host = self.url.host_port_subcomponent
         # host_subcomponent is None when the URL is a relative URL.
         # but we know we do not have a relative URL here.
         assert host is not None
-
-        if host[-1] == ".":
-            # Remove all trailing dots from the netloc as while
-            # they are valid FQDNs in DNS, TLS validation fails.
-            # See https://github.com/aio-libs/aiohttp/issues/3636.
-            # To avoid string manipulation we only call rstrip if
-            # the last character is a dot.
-            host = host.rstrip(".")
-
-        # If explicit port is not None, it means that the port was
-        # explicitly specified in the URL. In this case we check
-        # if its not the default port for the scheme and add it to
-        # the host header. We check explicit_port first because
-        # yarl caches explicit_port and its likely to already be
-        # in the cache and non-default port URLs are far less common.
-        explicit_port = self.url.explicit_port
-        if explicit_port is not None and not self.url.is_default_port():
-            host = f"{host}:{explicit_port}"
-
         self.headers[hdrs.HOST] = host
 
         if not headers:

@bdraco
Copy link
Member Author

bdraco commented Oct 22, 2024

Turns out to be super nice on performance since it ends up in the cache and subsequent calls to the same url again doesn't have to recalculated it again if it hits the LRU which turns out to be often

@bdraco bdraco marked this pull request as ready for review October 22, 2024 21:11
@bdraco bdraco marked this pull request as draft October 22, 2024 21:11
@bdraco bdraco marked this pull request as ready for review October 22, 2024 21:16
@bdraco bdraco enabled auto-merge (squash) October 22, 2024 21:16
@bdraco bdraco merged commit cc1ff18 into master Oct 22, 2024
44 of 46 checks passed
@bdraco bdraco deleted the host_port_subcompoment branch October 22, 2024 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant