Skip to main content

check_field_value

Function check_field_value 

Source
pub fn check_field_value(value: &[u8]) -> Result<(), ParseError>
Expand description

Validates a field value per RFC 9110 section 5.5: every byte is field-vchar, SP, HTAB, or obs-text.

This is the guard every engine runs on every field value. It does not strip OWS; an empty value is valid.

§Errors

ErrorKind::BareCr for CR, ErrorKind::LineFeed for LF, ErrorKind::Nul for NUL, and ErrorKind::Control for any other control byte or DEL, each at the offending offset.

§Examples

use parse_net::{scan::check_field_value, ErrorKind};

assert!(check_field_value(b"caf\xc3\xa9 \tok").is_ok());
assert_eq!(check_field_value(b"abcdefgh\x00").unwrap_err().kind(), ErrorKind::Nul);
assert_eq!(check_field_value(b"a\nb").unwrap_err().offset(), 1);