Repository navigation
Preserve explicit port 0 in connection_from_url and HTTP/2 authority - #5101
Merged
Merged
Conversation
illia-v
reviewed
Jul 12, 2026
Comment on lines
+130
to
+134
| port = self.port if self.port is not None else 443 | ||
| if ":" in self.host: | ||
| authority = f"[{self.host}]:{self.port or 443}" | ||
| authority = f"[{self.host}]:{port}" | ||
| else: | ||
| authority = f"{self.host}:{self.port or 443}" | ||
| authority = f"{self.host}:{port}" |
Member
There was a problem hiding this comment.
Please add a test covering these lines
Contributor
Author
There was a problem hiding this comment.
Done. Added test_request_authority_port_zero in test/test_http2_connection.py, it builds the request with port 0 and asserts the :authority header comes out as example.com:0. It fails against the old self.port or 443 (gives :443) and passes with the None check.
illia-v
approved these changes
Aug 2, 2026
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
connection_from_url() and the HTTP/2 request authority build the port with a truthiness check, so an explicit :0 in the URL gets dropped and replaced by the default 80 or 443. This is the same handling #5071 corrected for URL parsing, pool selection, and proxy configuration, but these two call sites were left using
port or <default>. Switching them to an explicit None check keeps an explicit port 0.