Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions lychee-bin/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 =
Expand Down
Loading