handle header with spaces before value
This commit is contained in:
@@ -94,6 +94,16 @@ impl FromStr for Header {
|
|||||||
return Err(Error::BadHeader);
|
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 })
|
Ok(Header { line, index })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,3 +151,16 @@ pub fn no_status_text() {
|
|||||||
assert!(resp.ok());
|
assert!(resp.ok());
|
||||||
assert_eq!(resp.status(), 200);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user