hyperium / http

Rust HTTP types
Apache License 2.0
1.15k stars 285 forks source link

Add sockaddr authority #624

Open mcr opened 1 year ago

mcr commented 1 year ago

This adds the ability to create an authority object from a SocketAddr.

While many web interactions start with a URL, there are others that start from a mDNS, DNS-SD or GRASP (RFC8990) discovery. IP addresses (often link-local), port numbers (and IPv6 scope) are returned from the discovery, but one then needs to form a URI for the relevant HTTP library. (Although the application usually has to open the socket itself, a URI is often still required for Host: header, and path+query string)

Perhaps this should be hidden behind some feature to avoid a dependency upon net. Probably this should also be behind no_std, since byte strings are created.

I was surprised that the URI was not parsed into pieces and pointed to separately, but I see the logic for this. I would prefer to put this into authority because that keeps the knowledge about what are valid and invalid URIs in one place. (Thank you, btw, for supporting RFC6874, and note draft-ietf-6man-rfc6874bis/ about to be published)

mcr commented 1 year ago

@becarpenter might have some test cases to add.

becarpenter commented 1 year ago

I don't have context to know what sort of test cases you would want. There are examples in draft-ietf-6man-rfc6874bis. Re RFC6874(bis), note that the bis document removes the need to replace "%" by "%25". The impact of that depends on fine details of the URL parser. My fix for the WGET parser is at https://github.com/becarpenter/wget6, and the way WGET is coded means that it accepts both RFC6874 and RFC6874bis formats.