-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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 |
Hey @waynr! Good suggestion, added another test case |
There was a problem hiding this 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?
Added it to the changelog |
maybe also add a link to the rfc in the code comment ? https://www.rfc-editor.org/rfc/rfc9110.html#name-host-and-authority |
3c141be
to
ed7d490
Compare
I've rebased to latest main and updated the comment to link to the RFC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, just looking through old PRs and found this.
I fixed the merge conflicts so you don't have to, but I have another questions before merging this, see below.
axum/src/extract/host.rs
Outdated
let mut parts = Request::new(()).into_parts().0; | ||
parts.uri = "https://127.0.0.1:1234/image.jpg".parse().unwrap(); | ||
let host = Host::from_request_parts(&mut parts, &()).await.unwrap(); | ||
assert_eq!(host.0, "127.0.0.1:1234"); | ||
|
||
parts.uri = "http://cool:user@[::1]:456/file.txt".parse().unwrap(); | ||
let host = Host::from_request_parts(&mut parts, &()).await.unwrap(); | ||
assert_eq!(host.0, "[::1]:456"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you completely rewrite this example to not use the test client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've re-introduced the test client in e4a109e
@bouk would you have time to address the comments and rebase your changes? If not, I can take over. |
@yanns I don't, feel free to take over this PR |
@jplatte the PR is ready for review again |
axum/CHANGELOG.md
Outdated
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
# Unreleased | |||
|
|||
- **fixed:** Include port number when parsing authority ([#2242]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in axum-extra's changelog, no? Also, it should mention that this affects the Host
extractor, it's currently very hard to tell what this is about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, the merge moved the files into axum-extra, but not the changelog :) good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation
The 'Host' header should include the port number. When extracting the host from
uri
we useuri.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