Repository navigation
URL keeps the default port when the scheme is uppercase (e.g. "HTTPS://example.com:443") #3804
Unanswered
charan-rathore
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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