mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 10:02:38 +01:00
H1 decoder should ignore headers case
This commit is contained in:
parent
b1001b80b7
commit
67df9399df
@ -94,20 +94,20 @@ pub(crate) trait MessageType: Sized {
|
|||||||
}
|
}
|
||||||
// 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 => {
|
||||||
ka = if let Ok(conn) = value.to_str() {
|
ka = if let Ok(conn) = value.to_str().map(|conn| conn.trim()) {
|
||||||
if conn.contains("keep-alive") {
|
if conn.eq_ignore_ascii_case("keep-alive") {
|
||||||
Some(ConnectionType::KeepAlive)
|
Some(ConnectionType::KeepAlive)
|
||||||
} else if conn.contains("close") {
|
} else if conn.eq_ignore_ascii_case("close") {
|
||||||
Some(ConnectionType::Close)
|
Some(ConnectionType::Close)
|
||||||
} else if conn.contains("upgrade") {
|
} else if conn.eq_ignore_ascii_case("upgrade") {
|
||||||
Some(ConnectionType::Upgrade)
|
Some(ConnectionType::Upgrade)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -120,8 +120,8 @@ pub(crate) trait MessageType: Sized {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -887,6 +887,14 @@ mod tests {
|
|||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert_eq!(req.inner().head.ctype, Some(ConnectionType::Close));
|
assert_eq!(req.inner().head.ctype, Some(ConnectionType::Close));
|
||||||
|
|
||||||
|
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_eq!(req.inner().head.ctype, Some(ConnectionType::Close));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -909,6 +917,15 @@ mod tests {
|
|||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert_eq!(req.inner().head.ctype, Some(ConnectionType::KeepAlive));
|
assert_eq!(req.inner().head.ctype, Some(ConnectionType::KeepAlive));
|
||||||
|
|
||||||
|
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_eq!(req.inner().head.ctype, Some(ConnectionType::KeepAlive));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -959,6 +976,17 @@ mod tests {
|
|||||||
|
|
||||||
assert!(req.upgrade());
|
assert!(req.upgrade());
|
||||||
assert_eq!(req.inner().head.ctype, Some(ConnectionType::Upgrade));
|
assert_eq!(req.inner().head.ctype, Some(ConnectionType::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());
|
||||||
|
assert_eq!(req.inner().head.ctype, Some(ConnectionType::Upgrade));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user