hyperium / http

Rust HTTP types
Apache License 2.0
1.16k stars 291 forks source link

Convenience methods to create URL authority from its parts #458

Open roblabla opened 3 years ago

roblabla commented 3 years ago

Currently, the only way to build an Authority object is to parse a string in the form <host>:<port>. This can be a bit inconvenient: In the case the host is an ipv6 address, it needs to be enclosed in [], and the developer will have to do a somewhat complex dance to go from a Host/Port pair to a proper authority string.

It'd be nice to have additional convenience methods, e.g.

// From a host and a port
impl TryFrom<(&str, u16)> for Authority {}

This way, if &str is an IPv6 address (which can be detected by trying to parse it with Ipv6Addr::parse), it can automatically be bracketed.