diff --git a/lychee-bin/src/parse.rs b/lychee-bin/src/parse.rs index b5a4cca732..f7fc4d62c3 100644 --- a/lychee-bin/src/parse.rs +++ b/lychee-bin/src/parse.rs @@ -4,15 +4,15 @@ use lychee_lib::{remap::Remaps, Base}; use std::time::Duration; /// Split a single HTTP header into a (key, value) tuple -fn read_header(input: &str) -> Result<(String, String)> { - let elements: Vec<_> = input.split('=').collect(); - if elements.len() != 2 { - return Err(anyhow!( +fn read_header(input: &str) -> Result<(String, String), anyhow::Error> { + if let Some((key, value)) = input.split_once('=') { + Ok((key.to_string(), value.to_string())) + } else { + Err(anyhow!( "Header value must be of the form key=value, got {}", input - )); + )) } - Ok((elements[0].into(), elements[1].into())) } /// Parse seconds into a `Duration` @@ -56,6 +56,16 @@ mod tests { assert_eq!(parse_headers(&["accept=text/html"]).unwrap(), custom); } + #[test] + fn test_parse_custom_headers_with_equals() { + let mut custom_with_equals = HeaderMap::new(); + custom_with_equals.insert("x-test", "check=this".parse().unwrap()); + assert_eq!( + parse_headers(&["x-test=check=this"]).unwrap(), + custom_with_equals + ); + } + #[test] fn test_parse_remap() { let remaps =