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

Perform port normalization for http, https, ws, wss, and ftp schemes. #1603

Merged
merged 1 commit into from
Apr 27, 2021

Conversation

tomchristie
Copy link
Member

Normalize the port component of URLs, so that...

assert httpx.URL("http://www.example.com") == httpx.URL("http://www.example.com:80")
print(httpx.URL("http://www.example.com:80"))  # URL('http://www.example.com')

Following this part of the WHATWG spec...

If url’s port is url’s scheme’s default port, then set url’s port to null.

And using the set of default ports as defined by https://url.spec.whatwg.org/#url-miscellaneous

I figure this probably helps iron away a few possible corner cases. It more neatly matches browser behaviour, and it's in line with other aspects of normalization that we're providing for, eg...

assert httpx.URL("http://WWW.EXAMPLE.COM") == httpx.URL("http://www.example.com")

It also has the nice property that url.netloc now properly encapsulates the same value that ought to be used for the value of the Host header.

@tomchristie tomchristie added the user-experience Ensuring that users have a good experience using the library label Apr 27, 2021
@tomchristie tomchristie added this to the v0.18 milestone Apr 27, 2021
Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

I'm happy enough with this. Thanks for the useful reference!

@tomchristie tomchristie merged commit 0a8b44e into master Apr 27, 2021
@tomchristie tomchristie deleted the port-normalization branch April 27, 2021 13:06
@tomchristie tomchristie mentioned this pull request Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants