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

Ensure we include the port when parsing authority #2242

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bouk
Copy link

@bouk bouk commented Sep 28, 2023

Motivation

The 'Host' header should include the port number. When extracting the host from uri we use uri.host() however, which strips off the port number to only include the hostname.

The existing test also didn't test the right thing, because the request would still include a Host header—it's added automatically by hyper and there's no way to turn that off from reqwest.

Solution

Re-implement the authority parsing method directly. This code is copied from the http crate, just without the port stripping: https://github.com/hyperium/http/blob/1a04e715f49c9ac3fe8195583e8c9959cbd368d3/src/uri/authority.rs#L487-L505

@waynr
Copy link
Contributor

waynr commented Sep 28, 2023

Hey @bouk long time no see! (we worked together very briefly a few years ago) What a coincidence that you would open your first PR here just before I open my first PR :)

One suggestion I have here is to add a test case to validate the split you are doing on @ to exclude the username:password portion of the authority.

@bouk
Copy link
Author

bouk commented Sep 29, 2023

Hey @waynr! Good suggestion, added another test case

Copy link
Member

@davidpdrsn davidpdrsn left a comment

Choose a reason for hiding this comment

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

Looks good!

Wanna update the changelog as well?

@bouk
Copy link
Author

bouk commented Nov 2, 2023

Added it to the changelog

@ttys3
Copy link
Contributor

ttys3 commented Nov 2, 2023

maybe also add a link to the rfc in the code comment ?

https://www.rfc-editor.org/rfc/rfc9110.html#name-host-and-authority

@bouk bouk force-pushed the bouk/extract-host-from-uri-port branch from 3c141be to ed7d490 Compare November 29, 2023 08:53
@bouk
Copy link
Author

bouk commented Nov 29, 2023

I've rebased to latest main and updated the comment to link to the RFC

@bouk bouk requested a review from davidpdrsn November 29, 2023 08:53
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.

None yet

4 participants