pub fn parse<'a>(
lines: &'a [&'a [u8]],
limits: &Limits,
) -> Result<ForwardedElements<'a>, ParseError>Expand description
Parses every Forwarded field line (RFC 7239 section 4).
IPv6 must be quoted and bracketed (for="[2001:db8::1]:4711"); an
unquoted IPv6 is refused because : and [ are not token characters.
Values containing quoted pairs are refused. proto must be http or
https.
§Errors
ErrorKind::DuplicateParameter (a known name twice in one element);
ErrorKind::InvalidAddress, ErrorKind::InvalidPort,
ErrorKind::InvalidHost; ErrorKind::Malformed for another proto;
ErrorKind::TooManyHops beyond Limits::max_hops; the list and
token errors, with ParseError::line set.
§Examples
use parse_net::{forwarded, Limits};
let lines: [&[u8]; 1] = [b"for=192.0.2.60;proto=http;by=203.0.113.43, for=\"[2001:db8:cafe::17]:4711\""];
let elems: Vec<_> = forwarded::parse(&lines, &Limits::DEFAULT)?.iter().collect();
assert_eq!(elems.len(), 2);
assert!(forwarded::parse(&[&b"for=2001:db8::1"[..]], &Limits::DEFAULT).is_err());