Skip to content

Fix port-zero handling - #5071

Merged
illia-v merged 2 commits into
urllib3:mainfrom
illia-v:fix-port-0
Jun 18, 2026
Merged

illia-v merged 2 commits into
urllib3:mainfrom
illia-v:fix-port-0

Conversation

@illia-v

@illia-v illia-v commented Jun 1, 2026

Copy link
Copy Markdown
Member

@christos-spearbit noticed that previously, when a new request passed port=0, pool selection treated that value as if no port had been provided at all, so it fell back to the scheme default (80 for HTTP or 443 for HTTPS) and reused the existing default-port pool instead of creating or selecting a distinct port-zero pool.

This change preserves port 0 as a distinct one in URL parsing, pool selection, and proxy configuration.

@sigmavirus24 sigmavirus24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to allow a pool for port 0? It's reserved and primarily reserved due to how POSIX works when trying to get the next available port number for binding a listener... So why do we want/need to handle this?

@illia-v

illia-v commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

@sigmavirus24 that's a good question!

My primary goal is to ensure that if a user explicitly requests port 0, urllib3 does not implicitly fall back to port 80 or 443.

While browsers like Firefox and Chrome block requests to port 0, curl will attempt the connection (as detailed in Daniel's blog post).

Personally, I think it's best to let the underlying operating system decide how to handle a port 0 request rather than blocking it at the library level. However, I'm indifferent to the exact behavior as long as we stop defaulting it to port 80/443.

@illia-v
illia-v merged commit f5cf122 into urllib3:main Jun 18, 2026
67 of 69 checks passed
@illia-v
illia-v deleted the fix-port-0 branch June 18, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants