handle header with spaces before value

This commit is contained in:
Martin Algesten
2019-10-20 10:58:16 +02:00
parent e936d5ea74
commit 999653e7f3
2 changed files with 23 additions and 0 deletions

View File

@@ -94,6 +94,16 @@ impl FromStr for Header {
return Err(Error::BadHeader);
}
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
// The field value MAY be preceded by any amount of LWS, though a single SP is preferred.
let value_from = &s[index..];
let voff = match value_from.find(|c: char| !c.is_whitespace()) {
Some(n) => n,
None => 0,
};
let index = index + voff;
Ok(Header { line, index })
}
}

View File

@@ -151,3 +151,16 @@ pub fn no_status_text() {
assert!(resp.ok());
assert_eq!(resp.status(), 200);
}
#[test]
pub fn header_with_spaces_before_value() {
test::set_handler("/space_before_value", |unit| {
assert!(unit.has("X-Test"));
assert_eq!(unit.header("X-Test").unwrap(), "value");
test::make_response(200, "OK", vec![], vec![])
});
let resp = get("test://host/space_before_value")
.set("X-Test", " value")
.call();
assert_eq!(resp.status(), 200);
}