Repository navigation
URL keeps the default port when the scheme is uppercase (e.g. "HTTPS://example.com:443") #3804
Replies: 2 comments
|
I independently reproduced this on HTTPX 0.28.1 and checked the proposed change against master One additional observable regression is that reparsing the string representation changes URL equality: u = httpx.URL("HTTPS://EXAMPLE.COM:443/a")
assert u == httpx.URL(str(u)) # Fails before the change.Using the already-normalized scheme, as you suggested, fixes this locally: - parsed_port: int | None = normalize_port(port, scheme)
+ parsed_port: int | None = normalize_port(port, parsed_scheme)I added 70 local checks covering lowercase/uppercase/mixed-case schemes, string construction, keyword construction and The full local suite is not entirely green: 1,485 passed, 1 skipped, 2 failed. The same two failures also occur on the unmodified checkout: This supports your proposed one-line change; it does not establish that the full CI/platform matrix passes. |
|
Thanks for the thorough verification, the scheme/casing matrix coverage is exactly what this needed. I have the one-liner plus regression tests on a branch (your equality-under-reparse case included): 7 of the 10 new tests fail on master, all 10 pass with the change, and the existing test_url.py suite stays green. The repo cu rrently limits new pull requests to collaborators, so I cannot open the PR yet; the branch is ready and I will open it as soon as the limit lifts. |
Uh oh!
There was an error while loading. Please reload this page.
httpx version: 0.28.1 (also current master, b5addb6)
Platform / Python: Linux, CPython 3.11
Smallest repro:
Same for
HTTP://EXAMPLE.COM:80/...(port 80 kept), and forWS/WSS/FTPequivalents.Expected: the default port is dropped regardless of scheme casing, as it is for lowercase input. RFC 3986 section 3.2.3 says normalizers should omit a port equal to the scheme's default, and WHATWG URL behaves the same way.
Cause: in
httpx/_urlparse.py,urlparse()lowercases the scheme intoparsed_scheme, but then callsnormalize_port(port, scheme)with the original scheme. The default-port map innormalize_port({"ftp": 21, "http": 80, "https": 443, "ws": 80, "wss": 443}) only has lowercase keys, so an uppercase scheme never matches its default port and the port survives normalization.Besides string output, this makes
url.portreturn443instead ofNone, breaks URL equality/comparison, and propagates into anything built on the normalized URL (Host header, redirect handling).Possible fix: pass the lowercased scheme into
normalize_port(one-line change:normalize_port(port, scheme.lower())or reuseparsed_scheme), plus a regression test. Happy to open a PR with that if you'd like.All reactions