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: an entity tag when the value starts with W/ or ", an IMF-fixdate otherwise.

§Errors

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

§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());