1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 16:02:59 +01:00

Merge branch 'master' of github.com:fafhrd91/actix-http

This commit is contained in:
Nikolay Kim 2018-12-19 18:35:09 -08:00
commit f2251b8059

View File

@ -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]