Skip to main content

Module host

Module host 

Source
Expand description

Host = uri-host [ ":" port ] (RFC 9110 section 7.2, citing RFC 3986 section 3.2.2), with real IPv4 and IPv6 validation.

§Examples

use core::net::Ipv6Addr;
use parse_net::{self as pn, Host, HostPort};

assert_eq!(pn::parse_host_port(b"[::1]:8080")?,
           HostPort { host: Host::V6(Ipv6Addr::LOCALHOST), port: Some(8080), empty_port: false });
assert_eq!(pn::parse_host_port(b"Example.COM.")?.host, Host::Name(b"Example.COM."));
assert_eq!(pn::parse_host_port(b"127.1").unwrap_err().kind(), pn::ErrorKind::InvalidAddress);
assert_eq!(pn::parse_host_port(b"a.com:80@b.com").unwrap_err().kind(), pn::ErrorKind::InvalidHost);

Structs§

HostPort
A host and an optional port.

Enums§

Host
A host: a registered name, an IP address, or a future IP literal.

Functions§

parse_host
Parses a host with no port.
parse_host_port
Parses a Host value: uri-host [ ":" port ].
parse_uri_host_port
Parses host [ ":" port ] exactly as given, for a URI authority or a request target: unlike parse_host_port, no OWS is stripped, so any whitespace is refused.