1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

fix test order dep

This commit is contained in:
Nikolay Kim 2019-11-06 11:20:47 -08:00
parent 885ff7396e
commit f7f410d033
2 changed files with 25 additions and 22 deletions

View File

@ -548,10 +548,11 @@ mod tests {
ConnectionType::Close, ConnectionType::Close,
&ServiceConfig::default(), &ServiceConfig::default(),
); );
assert_eq!( let data = String::from_utf8(Vec::from(bytes.take().freeze().as_ref())).unwrap();
bytes.take().freeze(), assert!(data.contains("Content-Length: 0\r\n"));
Bytes::from_static(b"\r\nContent-Length: 0\r\nConnection: close\r\nDate: date\r\nContent-Type: plain/text\r\n\r\n") assert!(data.contains("Connection: close\r\n"));
); assert!(data.contains("Content-Type: plain/text\r\n"));
assert!(data.contains("Date: date\r\n"));
let _ = head.encode_headers( let _ = head.encode_headers(
&mut bytes, &mut bytes,
@ -560,10 +561,10 @@ mod tests {
ConnectionType::KeepAlive, ConnectionType::KeepAlive,
&ServiceConfig::default(), &ServiceConfig::default(),
); );
assert_eq!( let data = String::from_utf8(Vec::from(bytes.take().freeze().as_ref())).unwrap();
bytes.take().freeze(), assert!(data.contains("Transfer-Encoding: chunked\r\n"));
Bytes::from_static(b"\r\nTransfer-Encoding: chunked\r\nDate: date\r\nContent-Type: plain/text\r\n\r\n") assert!(data.contains("Content-Type: plain/text\r\n"));
); assert!(data.contains("Date: date\r\n"));
let _ = head.encode_headers( let _ = head.encode_headers(
&mut bytes, &mut bytes,
@ -572,10 +573,10 @@ mod tests {
ConnectionType::KeepAlive, ConnectionType::KeepAlive,
&ServiceConfig::default(), &ServiceConfig::default(),
); );
assert_eq!( let data = String::from_utf8(Vec::from(bytes.take().freeze().as_ref())).unwrap();
bytes.take().freeze(), assert!(data.contains("Content-Length: 100\r\n"));
Bytes::from_static(b"\r\nContent-Length: 100\r\nDate: date\r\nContent-Type: plain/text\r\n\r\n") assert!(data.contains("Content-Type: plain/text\r\n"));
); assert!(data.contains("Date: date\r\n"));
let mut head = RequestHead::default(); let mut head = RequestHead::default();
head.set_camel_case_headers(false); head.set_camel_case_headers(false);
@ -586,7 +587,6 @@ mod tests {
.append(CONTENT_TYPE, HeaderValue::from_static("xml")); .append(CONTENT_TYPE, HeaderValue::from_static("xml"));
let mut head = RequestHeadType::Owned(head); let mut head = RequestHeadType::Owned(head);
let _ = head.encode_headers( let _ = head.encode_headers(
&mut bytes, &mut bytes,
Version::HTTP_11, Version::HTTP_11,
@ -594,10 +594,11 @@ mod tests {
ConnectionType::KeepAlive, ConnectionType::KeepAlive,
&ServiceConfig::default(), &ServiceConfig::default(),
); );
assert_eq!( let data = String::from_utf8(Vec::from(bytes.take().freeze().as_ref())).unwrap();
bytes.take().freeze(), assert!(data.contains("transfer-encoding: chunked\r\n"));
Bytes::from_static(b"\r\ntransfer-encoding: chunked\r\ndate: date\r\ncontent-type: xml\r\ncontent-type: plain/text\r\n\r\n") assert!(data.contains("content-type: xml\r\n"));
); assert!(data.contains("content-type: plain/text\r\n"));
assert!(data.contains("date: date\r\n"));
} }
#[test] #[test]
@ -626,9 +627,10 @@ mod tests {
ConnectionType::Close, ConnectionType::Close,
&ServiceConfig::default(), &ServiceConfig::default(),
); );
assert_eq!( let data = String::from_utf8(Vec::from(bytes.take().freeze().as_ref())).unwrap();
bytes.take().freeze(), assert!(data.contains("content-length: 0\r\n"));
Bytes::from_static(b"\r\ncontent-length: 0\r\nconnection: close\r\nauthorization: another authorization\r\ndate: date\r\n\r\n") assert!(data.contains("connection: close\r\n"));
); assert!(data.contains("authorization: another authorization\r\n"));
assert!(data.contains("date: date\r\n"));
} }
} }

View File

@ -276,7 +276,8 @@ pub fn Host<H: AsRef<str>>(host: H) -> HostGuard {
fn get_host_uri(req: &RequestHead) -> Option<Uri> { fn get_host_uri(req: &RequestHead) -> Option<Uri> {
use core::str::FromStr; use core::str::FromStr;
req.headers.get(header::HOST) req.headers
.get(header::HOST)
.and_then(|host_value| host_value.to_str().ok()) .and_then(|host_value| host_value.to_str().ok())
.or_else(|| req.uri.host()) .or_else(|| req.uri.host())
.map(|host: &str| Uri::from_str(host).ok()) .map(|host: &str| Uri::from_str(host).ok())