Skip to main content

parse_if_range

Function parse_if_range 

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

Parses If-Range without a clock: an entity tag when the value starts with W/ or ", an IMF-fixdate or asctime date otherwise. An RFC 850 date needs the current time to place its year, so it takes parse_if_range_at; here it is ErrorKind::InvalidDate.

§Errors

The errors of EntityTag::parse or HttpDate::parse_at.

§Examples

use parse_net::{range::parse_if_range, IfRange};

assert!(matches!(parse_if_range(b"\"abc\"")?, IfRange::Tag(t) if t.opaque() == b"abc"));
assert!(matches!(parse_if_range(b"Sun, 06 Nov 1994 08:49:37 GMT")?, IfRange::Date(_)));
assert!(parse_if_range(b"tomorrow").is_err());