Skip to content

Differentiate between 'url.host' and 'url.raw_host' - #1590

Merged
lovelydinosaur merged 7 commits into
masterfrom
raw-host
Apr 23, 2021
Merged

Differentiate between 'url.host' and 'url.raw_host'#1590
lovelydinosaur merged 7 commits into
masterfrom
raw-host

Conversation

@lovelydinosaur

@lovelydinosaurlovelydinosaur commented Apr 22, 2021

Copy link
Copy Markdown
Contributor

Refs #1275

Throughout our URL model we're differentiating neatly between byte-wise cases and str cases.
We're always using bytes when escaping is not applied, and str when escaping is applied.

Eg...

url=httpx.URL("https://jo%40email.com:a%20secret@example.com:1234/pa th")
asserturl.username=="jo@email.com"asserturl.password=="a secret"asserturl.userinfo==b"jo%40email.com:a%20secret"asserturl.path=="/pa th"asserturl.raw_path==b"/pa%20th"

This pull request is a proposal for treating IDNA domain names similarly, so...

url=httpx.URL("https://müller.de:80")
asserturl.host=="müller.de"asserturl.raw_host==b"xn--mller-kva.de"

For API consistency this also necessarily results in url.netloc becoming a byte interface, which actually makes sense for the contexts in which it is used.

url=httpx.URL("https://müller.de:80")
asserturl.netloc==b"xn--mller-kva.de:80"

Finally we also introduce .raw_scheme for a byte-wise representation of the scheme, for a nice consistency so that:

url=httpx.URL("https://müller.de:80/pa th")
asserturl.raw== (url.raw_scheme, url.raw_host, url.port, url.raw_path)
asserturl.raw== (b"https", b"xn--mller-kva.de", 80, b"/pa%20th")

@lovelydinosaurlovelydinosaur added the user-experience Ensuring that users have a good experience using the library label Apr 22, 2021
@StephenBrown2

Copy link
Copy Markdown
Contributor

Wouldn't raw indicate unencoded?

@StephenBrown2StephenBrown2 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.

Just a couple typos, and the previous question about what raw means.

Comment threadhttpx/_models.py Outdated
Comment threadhttpx/_models.py Outdated
Comment threadhttpx/_models.py Outdated
Comment threadhttpx/_models.py Outdated
Comment threadhttpx/_models.py Outdated
lovelydinosaurand others added 5 commits April 23, 2021 09:03
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
@lovelydinosaur

lovelydinosaur commented Apr 23, 2021

Copy link
Copy Markdown
ContributorAuthor

Raw, as in the "the raw bytes on the wire", or "the raw ingredients that make up the cake".
The raw representation of the host is the actual unaltered bytewise representation that's used to make the connection.

Or, in baking...

The raw ingredients: \xf0\x9f\x8e\x82
The cake: 🎂

Similar usage of "Raw" in other technical docs.

@lovelydinosaur

Copy link
Copy Markdown
ContributorAuthor

Thanks so much for the review @StephenBrown2.
(Geez, me & my typos. 😬)

@lovelydinosaur
lovelydinosaur merged commit 39d8ee6 into masterApr 23, 2021
@lovelydinosaur
lovelydinosaur deleted the raw-host branch April 23, 2021 10:00
@StephenBrown2

Copy link
Copy Markdown
Contributor

(Geez, me & my typos. 😬)

I think it was mainly just a copy-paste issue that got propagated, but no more normlized! :-p

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

user-experienceEnsuring that users have a good experience using the library

Development

Successfully merging this pull request may close these issues.

2 participants

@lovelydinosaur@StephenBrown2