pub fn split_list(value: &[u8]) -> ListElements<'_> ⓘExpand description
Split one instance of a list field into its elements, as RFC 9110 section 5.6.1 describes: a comma inside a quoted string does not separate elements, spaces and tabs around each element are removed, and empty elements are skipped.
Comments, the parenthesized text some fields such as Via allow (RFC 9110 section 5.6.5), are not recognized, so a comma inside one separates elements. A field type whose values can contain comments should use Separate and split its values itself.
use base_message::split_list;
let elements: Result<Vec<&[u8]>, _> = split_list(b"text/html, , application/json;q=\"0,9\"").collect();
assert_eq!(elements?, [&b"text/html"[..], &b"application/json;q=\"0,9\""[..]]);
assert!(split_list(b"a, \"b").any(|element| element.is_err()));The elements are produced without allocating. A quoted string that does not end is reported as an error after the elements before it, and then the iterator ends.