mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 11:31:09 +00:00
H1 decoded should ignore header cases
This commit is contained in:
parent
e8bdcb1c08
commit
1a940d4c18
3 changed files with 46 additions and 11 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.7.17] - 2018-xx-xx
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* HTTP1 decoder should perform case-insentive comparison for client requests (e.g. `Keep-Alive`). #631
|
||||||
|
|
||||||
## [0.7.16] - 2018-12-11
|
## [0.7.16] - 2018-12-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -942,6 +942,14 @@ mod tests {
|
||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(!req.keep_alive());
|
assert!(!req.keep_alive());
|
||||||
|
|
||||||
|
let mut buf = BytesMut::from(
|
||||||
|
"GET /test HTTP/1.1\r\n\
|
||||||
|
connection: Close\r\n\r\n",
|
||||||
|
);
|
||||||
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
|
assert!(!req.keep_alive());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -953,10 +961,26 @@ mod tests {
|
||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(!req.keep_alive());
|
assert!(!req.keep_alive());
|
||||||
|
|
||||||
|
let mut buf = BytesMut::from(
|
||||||
|
"GET /test HTTP/1.0\r\n\
|
||||||
|
connection: Close\r\n\r\n",
|
||||||
|
);
|
||||||
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
|
assert!(!req.keep_alive());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_conn_keep_alive_1_0() {
|
fn test_conn_keep_alive_1_0() {
|
||||||
|
let mut buf = BytesMut::from(
|
||||||
|
"GET /test HTTP/1.0\r\n\
|
||||||
|
connection: Keep-Alive\r\n\r\n",
|
||||||
|
);
|
||||||
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
|
assert!(req.keep_alive());
|
||||||
|
|
||||||
let mut buf = BytesMut::from(
|
let mut buf = BytesMut::from(
|
||||||
"GET /test HTTP/1.0\r\n\
|
"GET /test HTTP/1.0\r\n\
|
||||||
connection: keep-alive\r\n\r\n",
|
connection: keep-alive\r\n\r\n",
|
||||||
|
@ -1009,6 +1033,15 @@ mod tests {
|
||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(req.upgrade());
|
assert!(req.upgrade());
|
||||||
|
|
||||||
|
let mut buf = BytesMut::from(
|
||||||
|
"GET /test HTTP/1.1\r\n\
|
||||||
|
upgrade: Websockets\r\n\
|
||||||
|
connection: Upgrade\r\n\r\n",
|
||||||
|
);
|
||||||
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
|
assert!(req.upgrade());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -157,23 +157,19 @@ impl H1Decoder {
|
||||||
}
|
}
|
||||||
// transfer-encoding
|
// transfer-encoding
|
||||||
header::TRANSFER_ENCODING => {
|
header::TRANSFER_ENCODING => {
|
||||||
if let Ok(s) = value.to_str() {
|
if let Ok(s) = value.to_str().map(|s| s.trim()) {
|
||||||
chunked = s.to_lowercase().contains("chunked");
|
chunked = s.eq_ignore_ascii_case("chunked");
|
||||||
} else {
|
} else {
|
||||||
return Err(ParseError::Header);
|
return Err(ParseError::Header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// connection keep-alive state
|
// connection keep-alive state
|
||||||
header::CONNECTION => {
|
header::CONNECTION => {
|
||||||
let ka = if let Ok(conn) = value.to_str() {
|
let ka = if let Ok(conn) = value.to_str().map(|conn| conn.trim()) {
|
||||||
if version == Version::HTTP_10
|
if version == Version::HTTP_10 && conn.eq_ignore_ascii_case("keep-alive") {
|
||||||
&& conn.contains("keep-alive")
|
|
||||||
{
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
version == Version::HTTP_11 && !(conn
|
version == Version::HTTP_11 && !(conn.eq_ignore_ascii_case("close") || conn.eq_ignore_ascii_case("upgrade"))
|
||||||
.contains("close")
|
|
||||||
|| conn.contains("upgrade"))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -184,8 +180,8 @@ impl H1Decoder {
|
||||||
has_upgrade = true;
|
has_upgrade = true;
|
||||||
// check content-length, some clients (dart)
|
// check content-length, some clients (dart)
|
||||||
// sends "content-length: 0" with websocket upgrade
|
// sends "content-length: 0" with websocket upgrade
|
||||||
if let Ok(val) = value.to_str() {
|
if let Ok(val) = value.to_str().map(|val| val.trim()) {
|
||||||
if val == "websocket" {
|
if val.eq_ignore_ascii_case("websocket") {
|
||||||
content_length = None;
|
content_length = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue