Skip to main content

parse_uri_host_port

Function parse_uri_host_port 

Source
pub fn parse_uri_host_port(value: &[u8]) -> Result<HostPort<'_>, ParseError>
Expand description

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.

Use this wherever the bytes are not a field value: an authority-form or absolute-form request target, a URL, a Forwarded node. Stripping whitespace there would accept CONNECT example.com:443 (two spaces), which other parsers refuse.

§Errors

As parse_host_port; whitespace is refused like any other byte outside the grammar (ErrorKind::InvalidHost in the host, ErrorKind::InvalidPort after a port).

§Examples

use parse_net::{host::parse_uri_host_port, parse_host_port};

assert!(parse_host_port(b" example.com:443").is_ok());
assert!(parse_uri_host_port(b" example.com:443").is_err());
assert_eq!(parse_uri_host_port(b"example.com:443")?.port, Some(443));