axum icon indicating copy to clipboard operation
axum copied to clipboard

Ensure we include the port when parsing authority

Open bouk opened this issue 9 months ago • 5 comments

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

bouk avatar Sep 28 '23 07:09 bouk

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.

waynr avatar Sep 28 '23 22:09 waynr

Hey @waynr! Good suggestion, added another test case

bouk avatar Sep 29 '23 10:09 bouk

Added it to the changelog

bouk avatar Nov 02 '23 11:11 bouk

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

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

ttys3 avatar Nov 02 '23 16:11 ttys3

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

bouk avatar Nov 29 '23 08:11 bouk