mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
update tests
This commit is contained in:
parent
2e83c5924d
commit
55204c829c
@ -310,7 +310,6 @@ mod tests {
|
|||||||
use http::{Method, Version, Uri, HeaderMap, StatusCode};
|
use http::{Method, Version, Uri, HeaderMap, StatusCode};
|
||||||
use super::*;
|
use super::*;
|
||||||
use httprequest::HttpRequest;
|
use httprequest::HttpRequest;
|
||||||
use payload::Payload;
|
|
||||||
use httpcodes;
|
use httpcodes;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -321,13 +320,13 @@ mod tests {
|
|||||||
|
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/test").unwrap(),
|
Method::GET, Uri::from_str("/test").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
assert_eq!(resp.as_response().unwrap().status(), StatusCode::OK);
|
assert_eq!(resp.as_response().unwrap().status(), StatusCode::OK);
|
||||||
|
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/blah").unwrap(),
|
Method::GET, Uri::from_str("/blah").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
|
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
|
||||||
|
|
||||||
@ -336,7 +335,7 @@ mod tests {
|
|||||||
.finish();
|
.finish();
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/blah").unwrap(),
|
Method::GET, Uri::from_str("/blah").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
assert_eq!(resp.as_response().unwrap().status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(resp.as_response().unwrap().status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
}
|
}
|
||||||
|
56
src/h1.rs
56
src/h1.rs
@ -998,7 +998,7 @@ mod tests {
|
|||||||
assert_eq!(req.version(), Version::HTTP_11);
|
assert_eq!(req.version(), Version::HTTP_11);
|
||||||
assert_eq!(*req.method(), Method::GET);
|
assert_eq!(*req.method(), Method::GET);
|
||||||
assert_eq!(req.path(), "/test");
|
assert_eq!(req.path(), "/test");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().is_none());
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1021,7 +1021,7 @@ mod tests {
|
|||||||
assert_eq!(req.version(), Version::HTTP_11);
|
assert_eq!(req.version(), Version::HTTP_11);
|
||||||
assert_eq!(*req.method(), Method::PUT);
|
assert_eq!(*req.method(), Method::PUT);
|
||||||
assert_eq!(req.path(), "/test");
|
assert_eq!(req.path(), "/test");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().is_none());
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1038,7 +1038,7 @@ mod tests {
|
|||||||
assert_eq!(req.version(), Version::HTTP_10);
|
assert_eq!(req.version(), Version::HTTP_10);
|
||||||
assert_eq!(*req.method(), Method::POST);
|
assert_eq!(*req.method(), Method::POST);
|
||||||
assert_eq!(req.path(), "/test2");
|
assert_eq!(req.path(), "/test2");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().is_none());
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1055,7 +1055,7 @@ mod tests {
|
|||||||
assert_eq!(req.version(), Version::HTTP_11);
|
assert_eq!(req.version(), Version::HTTP_11);
|
||||||
assert_eq!(*req.method(), Method::GET);
|
assert_eq!(*req.method(), Method::GET);
|
||||||
assert_eq!(req.path(), "/test");
|
assert_eq!(req.path(), "/test");
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"body");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"body");
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1073,7 +1073,7 @@ mod tests {
|
|||||||
assert_eq!(req.version(), Version::HTTP_11);
|
assert_eq!(req.version(), Version::HTTP_11);
|
||||||
assert_eq!(*req.method(), Method::GET);
|
assert_eq!(*req.method(), Method::GET);
|
||||||
assert_eq!(req.path(), "/test");
|
assert_eq!(req.path(), "/test");
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"body");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"body");
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1093,7 +1093,7 @@ mod tests {
|
|||||||
assert_eq!(req.version(), Version::HTTP_11);
|
assert_eq!(req.version(), Version::HTTP_11);
|
||||||
assert_eq!(*req.method(), Method::GET);
|
assert_eq!(*req.method(), Method::GET);
|
||||||
assert_eq!(req.path(), "/test");
|
assert_eq!(req.path(), "/test");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().is_none());
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1120,7 +1120,7 @@ mod tests {
|
|||||||
assert_eq!(*req.method(), Method::GET);
|
assert_eq!(*req.method(), Method::GET);
|
||||||
assert_eq!(req.path(), "/test");
|
assert_eq!(req.path(), "/test");
|
||||||
assert_eq!(req.headers().get("test").unwrap().as_bytes(), b"value");
|
assert_eq!(req.headers().get("test").unwrap().as_bytes(), b"value");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().is_none());
|
||||||
}
|
}
|
||||||
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
Ok(_) | Err(_) => panic!("Error during parsing http request"),
|
||||||
}
|
}
|
||||||
@ -1229,7 +1229,7 @@ mod tests {
|
|||||||
connection: upgrade\r\n\r\n");
|
connection: upgrade\r\n\r\n");
|
||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
assert!(req.upgrade());
|
assert!(req.upgrade());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1241,7 +1241,7 @@ mod tests {
|
|||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(req.upgrade());
|
assert!(req.upgrade());
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1251,7 +1251,7 @@ mod tests {
|
|||||||
transfer-encoding: chunked\r\n\r\n");
|
transfer-encoding: chunked\r\n\r\n");
|
||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(!req.payload().eof());
|
assert!(req.payload().is_some());
|
||||||
if let Ok(val) = req.chunked() {
|
if let Ok(val) = req.chunked() {
|
||||||
assert!(val);
|
assert!(val);
|
||||||
} else {
|
} else {
|
||||||
@ -1263,7 +1263,7 @@ mod tests {
|
|||||||
transfer-encoding: chnked\r\n\r\n");
|
transfer-encoding: chnked\r\n\r\n");
|
||||||
let req = parse_ready!(&mut buf);
|
let req = parse_ready!(&mut buf);
|
||||||
|
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().is_none());
|
||||||
if let Ok(val) = req.chunked() {
|
if let Ok(val) = req.chunked() {
|
||||||
assert!(!val);
|
assert!(!val);
|
||||||
} else {
|
} else {
|
||||||
@ -1323,7 +1323,7 @@ mod tests {
|
|||||||
let mut req = parse_ready!(&mut buf);
|
let mut req = parse_ready!(&mut buf);
|
||||||
assert!(!req.keep_alive());
|
assert!(!req.keep_alive());
|
||||||
assert!(req.upgrade());
|
assert!(req.upgrade());
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"some raw data");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"some raw data");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1371,13 +1371,13 @@ mod tests {
|
|||||||
let mut reader = Reader::new();
|
let mut reader = Reader::new();
|
||||||
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
|
|
||||||
buf.feed_data("4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n");
|
buf.feed_data("4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n");
|
||||||
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"dataline");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"dataline");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().unwrap().eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1391,7 +1391,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
|
|
||||||
buf.feed_data(
|
buf.feed_data(
|
||||||
"4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n\
|
"4\r\ndata\r\n4\r\nline\r\n0\r\n\r\n\
|
||||||
@ -1401,10 +1401,10 @@ mod tests {
|
|||||||
let req2 = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
let req2 = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert_eq!(*req2.method(), Method::POST);
|
assert_eq!(*req2.method(), Method::POST);
|
||||||
assert!(req2.chunked().unwrap());
|
assert!(req2.chunked().unwrap());
|
||||||
assert!(!req2.payload().eof());
|
assert!(!req2.payload().unwrap().eof());
|
||||||
|
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"dataline");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"dataline");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().unwrap().eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1417,7 +1417,7 @@ mod tests {
|
|||||||
let mut reader = Reader::new();
|
let mut reader = Reader::new();
|
||||||
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
|
|
||||||
buf.feed_data("4\r\ndata\r");
|
buf.feed_data("4\r\ndata\r");
|
||||||
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
@ -1439,12 +1439,12 @@ mod tests {
|
|||||||
//buf.feed_data("test: test\r\n");
|
//buf.feed_data("test: test\r\n");
|
||||||
//not_ready!(reader.parse(&mut buf, &mut readbuf));
|
//not_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
|
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"dataline");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"dataline");
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
|
|
||||||
buf.feed_data("\r\n");
|
buf.feed_data("\r\n");
|
||||||
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().unwrap().eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1457,13 +1457,13 @@ mod tests {
|
|||||||
let mut reader = Reader::new();
|
let mut reader = Reader::new();
|
||||||
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
let mut req = reader_parse_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
|
|
||||||
buf.feed_data("4;test\r\ndata\r\n4\r\nline\r\n0\r\n\r\n"); // test: test\r\n\r\n")
|
buf.feed_data("4;test\r\ndata\r\n4\r\nline\r\n0\r\n\r\n"); // test: test\r\n\r\n")
|
||||||
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
not_ready!(reader.parse(&mut buf, &mut readbuf));
|
||||||
assert!(!req.payload().eof());
|
assert!(!req.payload().unwrap().eof());
|
||||||
assert_eq!(req.payload_mut().readall().unwrap().as_ref(), b"dataline");
|
assert_eq!(req.payload_mut().unwrap().readall().unwrap().as_ref(), b"dataline");
|
||||||
assert!(req.payload().eof());
|
assert!(req.payload().unwrap().eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*#[test]
|
/*#[test]
|
||||||
|
@ -114,7 +114,7 @@ impl HttpRequest<()> {
|
|||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
cookies: None,
|
cookies: None,
|
||||||
addr: None,
|
addr: None,
|
||||||
payload: Payload::empty(),
|
payload: None,
|
||||||
extensions: Extensions::new(),
|
extensions: Extensions::new(),
|
||||||
info: None,
|
info: None,
|
||||||
}),
|
}),
|
||||||
@ -530,7 +530,6 @@ mod tests {
|
|||||||
use http::Uri;
|
use http::Uri;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use router::Pattern;
|
use router::Pattern;
|
||||||
use payload::Payload;
|
|
||||||
use resource::Resource;
|
use resource::Resource;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -539,8 +538,7 @@ mod tests {
|
|||||||
headers.insert(header::TRANSFER_ENCODING,
|
headers.insert(header::TRANSFER_ENCODING,
|
||||||
header::HeaderValue::from_static("chunked"));
|
header::HeaderValue::from_static("chunked"));
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
|
|
||||||
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::Chunked);
|
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::Chunked);
|
||||||
|
|
||||||
@ -550,8 +548,7 @@ mod tests {
|
|||||||
headers.insert(header::CONTENT_LENGTH,
|
headers.insert(header::CONTENT_LENGTH,
|
||||||
header::HeaderValue::from_static("xxxx"));
|
header::HeaderValue::from_static("xxxx"));
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11,
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
headers, Payload::empty());
|
|
||||||
|
|
||||||
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::UnknownLength);
|
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::UnknownLength);
|
||||||
|
|
||||||
@ -561,8 +558,7 @@ mod tests {
|
|||||||
headers.insert(header::CONTENT_LENGTH,
|
headers.insert(header::CONTENT_LENGTH,
|
||||||
header::HeaderValue::from_static("1000000"));
|
header::HeaderValue::from_static("1000000"));
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
|
|
||||||
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::Overflow);
|
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::Overflow);
|
||||||
|
|
||||||
@ -572,8 +568,7 @@ mod tests {
|
|||||||
headers.insert(header::CONTENT_LENGTH,
|
headers.insert(header::CONTENT_LENGTH,
|
||||||
header::HeaderValue::from_static("10"));
|
header::HeaderValue::from_static("10"));
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
|
|
||||||
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::ContentType);
|
assert_eq!(req.urlencoded().err().unwrap(), UrlencodedError::ContentType);
|
||||||
}
|
}
|
||||||
@ -584,8 +579,7 @@ mod tests {
|
|||||||
headers.insert(header::HOST,
|
headers.insert(header::HOST,
|
||||||
header::HeaderValue::from_static("www.rust-lang.org"));
|
header::HeaderValue::from_static("www.rust-lang.org"));
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
|
|
||||||
let mut resource = Resource::default();
|
let mut resource = Resource::default();
|
||||||
resource.name("index");
|
resource.name("index");
|
||||||
@ -612,7 +606,7 @@ mod tests {
|
|||||||
fn test_url_for_external() {
|
fn test_url_for_external() {
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
|
|
||||||
let mut resource = Resource::<()>::default();
|
let mut resource = Resource::<()>::default();
|
||||||
resource.name("index");
|
resource.name("index");
|
||||||
|
@ -291,7 +291,6 @@ mod tests {
|
|||||||
use time;
|
use time;
|
||||||
use http::{Method, Version, StatusCode, Uri};
|
use http::{Method, Version, StatusCode, Uri};
|
||||||
use http::header::{self, HeaderMap};
|
use http::header::{self, HeaderMap};
|
||||||
use payload::Payload;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_logger() {
|
fn test_logger() {
|
||||||
@ -300,8 +299,7 @@ mod tests {
|
|||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::USER_AGENT, header::HeaderValue::from_static("ACTIX-WEB"));
|
headers.insert(header::USER_AGENT, header::HeaderValue::from_static("ACTIX-WEB"));
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
let resp = HttpResponse::build(StatusCode::OK)
|
let resp = HttpResponse::build(StatusCode::OK)
|
||||||
.header("X-Test", "ttt")
|
.header("X-Test", "ttt")
|
||||||
.force_close().body(Body::Empty).unwrap();
|
.force_close().body(Body::Empty).unwrap();
|
||||||
@ -332,8 +330,7 @@ mod tests {
|
|||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::USER_AGENT, header::HeaderValue::from_static("ACTIX-WEB"));
|
headers.insert(header::USER_AGENT, header::HeaderValue::from_static("ACTIX-WEB"));
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
let resp = HttpResponse::build(StatusCode::OK)
|
let resp = HttpResponse::build(StatusCode::OK)
|
||||||
.force_close().body(Body::Empty).unwrap();
|
.force_close().body(Body::Empty).unwrap();
|
||||||
let entry_time = time::now();
|
let entry_time = time::now();
|
||||||
@ -351,7 +348,7 @@ mod tests {
|
|||||||
|
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/?test").unwrap(),
|
Method::GET, Uri::from_str("/?test").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
let resp = HttpResponse::build(StatusCode::OK)
|
let resp = HttpResponse::build(StatusCode::OK)
|
||||||
.force_close().body(Body::Empty).unwrap();
|
.force_close().body(Body::Empty).unwrap();
|
||||||
let entry_time = time::now();
|
let entry_time = time::now();
|
||||||
|
24
src/pred.rs
24
src/pred.rs
@ -153,7 +153,6 @@ mod tests {
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use http::{Uri, Version, Method};
|
use http::{Uri, Version, Method};
|
||||||
use http::header::{self, HeaderMap};
|
use http::header::{self, HeaderMap};
|
||||||
use payload::Payload;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_header() {
|
fn test_header() {
|
||||||
@ -161,8 +160,7 @@ mod tests {
|
|||||||
headers.insert(header::TRANSFER_ENCODING,
|
headers.insert(header::TRANSFER_ENCODING,
|
||||||
header::HeaderValue::from_static("chunked"));
|
header::HeaderValue::from_static("chunked"));
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
|
|
||||||
let pred = Header("transfer-encoding", "chunked");
|
let pred = Header("transfer-encoding", "chunked");
|
||||||
assert!(pred.check(&mut req));
|
assert!(pred.check(&mut req));
|
||||||
@ -178,10 +176,10 @@ mod tests {
|
|||||||
fn test_methods() {
|
fn test_methods() {
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
let mut req2 = HttpRequest::new(
|
let mut req2 = HttpRequest::new(
|
||||||
Method::POST, Uri::from_str("/").unwrap(),
|
Method::POST, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
|
|
||||||
assert!(Get().check(&mut req));
|
assert!(Get().check(&mut req));
|
||||||
assert!(!Get().check(&mut req2));
|
assert!(!Get().check(&mut req2));
|
||||||
@ -190,43 +188,43 @@ mod tests {
|
|||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::PUT, Uri::from_str("/").unwrap(),
|
Method::PUT, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Put().check(&mut r));
|
assert!(Put().check(&mut r));
|
||||||
assert!(!Put().check(&mut req));
|
assert!(!Put().check(&mut req));
|
||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::DELETE, Uri::from_str("/").unwrap(),
|
Method::DELETE, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Delete().check(&mut r));
|
assert!(Delete().check(&mut r));
|
||||||
assert!(!Delete().check(&mut req));
|
assert!(!Delete().check(&mut req));
|
||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::HEAD, Uri::from_str("/").unwrap(),
|
Method::HEAD, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Head().check(&mut r));
|
assert!(Head().check(&mut r));
|
||||||
assert!(!Head().check(&mut req));
|
assert!(!Head().check(&mut req));
|
||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::OPTIONS, Uri::from_str("/").unwrap(),
|
Method::OPTIONS, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Options().check(&mut r));
|
assert!(Options().check(&mut r));
|
||||||
assert!(!Options().check(&mut req));
|
assert!(!Options().check(&mut req));
|
||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::CONNECT, Uri::from_str("/").unwrap(),
|
Method::CONNECT, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Connect().check(&mut r));
|
assert!(Connect().check(&mut r));
|
||||||
assert!(!Connect().check(&mut req));
|
assert!(!Connect().check(&mut req));
|
||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::PATCH, Uri::from_str("/").unwrap(),
|
Method::PATCH, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Patch().check(&mut r));
|
assert!(Patch().check(&mut r));
|
||||||
assert!(!Patch().check(&mut req));
|
assert!(!Patch().check(&mut req));
|
||||||
|
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::TRACE, Uri::from_str("/").unwrap(),
|
Method::TRACE, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(Trace().check(&mut r));
|
assert!(Trace().check(&mut r));
|
||||||
assert!(!Trace().check(&mut req));
|
assert!(!Trace().check(&mut req));
|
||||||
}
|
}
|
||||||
@ -235,7 +233,7 @@ mod tests {
|
|||||||
fn test_preds() {
|
fn test_preds() {
|
||||||
let mut r = HttpRequest::new(
|
let mut r = HttpRequest::new(
|
||||||
Method::TRACE, Uri::from_str("/").unwrap(),
|
Method::TRACE, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
|
|
||||||
assert!(Not(Get()).check(&mut r));
|
assert!(Not(Get()).check(&mut r));
|
||||||
assert!(!Not(Trace()).check(&mut r));
|
assert!(!Not(Trace()).check(&mut r));
|
||||||
|
@ -305,7 +305,6 @@ mod tests {
|
|||||||
use http::{Uri, Version, Method};
|
use http::{Uri, Version, Method};
|
||||||
use http::header::HeaderMap;
|
use http::header::HeaderMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use payload::Payload;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_recognizer() {
|
fn test_recognizer() {
|
||||||
@ -320,39 +319,39 @@ mod tests {
|
|||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/name").unwrap(),
|
Method::GET, Uri::from_str("/name").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(rec.recognize(&mut req).is_some());
|
assert!(rec.recognize(&mut req).is_some());
|
||||||
assert!(req.match_info().is_empty());
|
assert!(req.match_info().is_empty());
|
||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/name/value").unwrap(),
|
Method::GET, Uri::from_str("/name/value").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(rec.recognize(&mut req).is_some());
|
assert!(rec.recognize(&mut req).is_some());
|
||||||
assert_eq!(req.match_info().get("val").unwrap(), "value");
|
assert_eq!(req.match_info().get("val").unwrap(), "value");
|
||||||
assert_eq!(&req.match_info()["val"], "value");
|
assert_eq!(&req.match_info()["val"], "value");
|
||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/name/value2/index.html").unwrap(),
|
Method::GET, Uri::from_str("/name/value2/index.html").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(rec.recognize(&mut req).is_some());
|
assert!(rec.recognize(&mut req).is_some());
|
||||||
assert_eq!(req.match_info().get("val").unwrap(), "value2");
|
assert_eq!(req.match_info().get("val").unwrap(), "value2");
|
||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/vtest/ttt/index.html").unwrap(),
|
Method::GET, Uri::from_str("/vtest/ttt/index.html").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(rec.recognize(&mut req).is_some());
|
assert!(rec.recognize(&mut req).is_some());
|
||||||
assert_eq!(req.match_info().get("val").unwrap(), "test");
|
assert_eq!(req.match_info().get("val").unwrap(), "test");
|
||||||
assert_eq!(req.match_info().get("val2").unwrap(), "ttt");
|
assert_eq!(req.match_info().get("val2").unwrap(), "ttt");
|
||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/v/blah-blah/index.html").unwrap(),
|
Method::GET, Uri::from_str("/v/blah-blah/index.html").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(rec.recognize(&mut req).is_some());
|
assert!(rec.recognize(&mut req).is_some());
|
||||||
assert_eq!(req.match_info().get("tail").unwrap(), "blah-blah/index.html");
|
assert_eq!(req.match_info().get("tail").unwrap(), "blah-blah/index.html");
|
||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let mut req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/bbb/index.html").unwrap(),
|
Method::GET, Uri::from_str("/bbb/index.html").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert!(rec.recognize(&mut req).is_some());
|
assert!(rec.recognize(&mut req).is_some());
|
||||||
assert_eq!(req.match_info().get("test").unwrap(), "bbb");
|
assert_eq!(req.match_info().get("test").unwrap(), "bbb");
|
||||||
}
|
}
|
||||||
|
17
src/ws.rs
17
src/ws.rs
@ -339,31 +339,30 @@ impl WsWriter {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use payload::Payload;
|
|
||||||
use http::{Method, HeaderMap, Version, Uri, header};
|
use http::{Method, HeaderMap, Version, Uri, header};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_handshake() {
|
fn test_handshake() {
|
||||||
let req = HttpRequest::new(Method::POST, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::POST, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
header::HeaderValue::from_static("test"));
|
header::HeaderValue::from_static("test"));
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"));
|
header::HeaderValue::from_static("websocket"));
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert_eq!(WsHandshakeError::NoConnectionUpgrade, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoConnectionUpgrade, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
@ -372,7 +371,7 @@ mod tests {
|
|||||||
headers.insert(header::CONNECTION,
|
headers.insert(header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"));
|
header::HeaderValue::from_static("upgrade"));
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert_eq!(WsHandshakeError::NoVersionHeader, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoVersionHeader, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
@ -383,7 +382,7 @@ mod tests {
|
|||||||
headers.insert(SEC_WEBSOCKET_VERSION,
|
headers.insert(SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("5"));
|
header::HeaderValue::from_static("5"));
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert_eq!(WsHandshakeError::UnsupportedVersion, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::UnsupportedVersion, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
@ -394,7 +393,7 @@ mod tests {
|
|||||||
headers.insert(SEC_WEBSOCKET_VERSION,
|
headers.insert(SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"));
|
header::HeaderValue::from_static("13"));
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert_eq!(WsHandshakeError::BadWebsocketKey, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::BadWebsocketKey, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
@ -407,7 +406,7 @@ mod tests {
|
|||||||
headers.insert(SEC_WEBSOCKET_KEY,
|
headers.insert(SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"));
|
header::HeaderValue::from_static("13"));
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert_eq!(StatusCode::SWITCHING_PROTOCOLS, handshake(&req).unwrap().status());
|
assert_eq!(StatusCode::SWITCHING_PROTOCOLS, handshake(&req).unwrap().status());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,14 @@ use http::{header, Method, Version, HeaderMap, Uri};
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_debug() {
|
fn test_debug() {
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11,
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, HeaderMap::new(), None);
|
||||||
HeaderMap::new(), Payload::empty());
|
|
||||||
let _ = format!("{:?}", req);
|
let _ = format!("{:?}", req);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_request_cookies() {
|
fn test_no_request_cookies() {
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, HeaderMap::new(), None);
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
|
||||||
assert!(req.cookies().unwrap().is_empty());
|
assert!(req.cookies().unwrap().is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,8 +31,7 @@ fn test_request_cookies() {
|
|||||||
header::HeaderValue::from_static("cookie1=value1; cookie2=value2"));
|
header::HeaderValue::from_static("cookie1=value1; cookie2=value2"));
|
||||||
|
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
|
||||||
{
|
{
|
||||||
let cookies = req.cookies().unwrap();
|
let cookies = req.cookies().unwrap();
|
||||||
assert_eq!(cookies.len(), 2);
|
assert_eq!(cookies.len(), 2);
|
||||||
@ -57,7 +54,7 @@ fn test_request_cookies() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_no_request_range_header() {
|
fn test_no_request_range_header() {
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
let ranges = req.range(100).unwrap();
|
let ranges = req.range(100).unwrap();
|
||||||
assert!(ranges.is_empty());
|
assert!(ranges.is_empty());
|
||||||
}
|
}
|
||||||
@ -69,7 +66,7 @@ fn test_request_range_header() {
|
|||||||
header::HeaderValue::from_static("bytes=0-4"));
|
header::HeaderValue::from_static("bytes=0-4"));
|
||||||
|
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
let ranges = req.range(100).unwrap();
|
let ranges = req.range(100).unwrap();
|
||||||
assert_eq!(ranges.len(), 1);
|
assert_eq!(ranges.len(), 1);
|
||||||
assert_eq!(ranges[0].start, 0);
|
assert_eq!(ranges[0].start, 0);
|
||||||
@ -79,7 +76,7 @@ fn test_request_range_header() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_request_query() {
|
fn test_request_query() {
|
||||||
let req = HttpRequest::new(Method::GET, Uri::from_str("/?id=test").unwrap(),
|
let req = HttpRequest::new(Method::GET, Uri::from_str("/?id=test").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
assert_eq!(req.query_string(), "id=test");
|
assert_eq!(req.query_string(), "id=test");
|
||||||
let query = req.query();
|
let query = req.query();
|
||||||
assert_eq!(&query["id"], "test");
|
assert_eq!(&query["id"], "test");
|
||||||
@ -88,7 +85,7 @@ fn test_request_query() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_request_match_info() {
|
fn test_request_match_info() {
|
||||||
let mut req = HttpRequest::new(Method::GET, Uri::from_str("/value/?id=test").unwrap(),
|
let mut req = HttpRequest::new(Method::GET, Uri::from_str("/value/?id=test").unwrap(),
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
Version::HTTP_11, HeaderMap::new(), None);
|
||||||
|
|
||||||
let mut resource = Resource::default();
|
let mut resource = Resource::default();
|
||||||
resource.name("index");
|
resource.name("index");
|
||||||
@ -103,16 +100,14 @@ fn test_request_match_info() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_chunked() {
|
fn test_chunked() {
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, HeaderMap::new(), None);
|
||||||
Version::HTTP_11, HeaderMap::new(), Payload::empty());
|
|
||||||
assert!(!req.chunked().unwrap());
|
assert!(!req.chunked().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::TRANSFER_ENCODING,
|
headers.insert(header::TRANSFER_ENCODING,
|
||||||
header::HeaderValue::from_static("chunked"));
|
header::HeaderValue::from_static("chunked"));
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11,
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
headers, Payload::empty());
|
|
||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
@ -122,6 +117,6 @@ fn test_chunked() {
|
|||||||
header::HeaderValue::from_str(s).unwrap());
|
header::HeaderValue::from_str(s).unwrap());
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(),
|
Method::GET, Uri::from_str("/").unwrap(),
|
||||||
Version::HTTP_11, headers, Payload::empty());
|
Version::HTTP_11, headers, None);
|
||||||
assert!(req.chunked().is_err());
|
assert!(req.chunked().is_err());
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ fn test_response_cookies() {
|
|||||||
header::HeaderValue::from_static("cookie1=value1; cookie2=value2"));
|
header::HeaderValue::from_static("cookie1=value1; cookie2=value2"));
|
||||||
|
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, Payload::empty());
|
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
|
||||||
let cookies = req.cookies().unwrap();
|
let cookies = req.cookies().unwrap();
|
||||||
|
|
||||||
let resp = httpcodes::HTTPOk
|
let resp = httpcodes::HTTPOk
|
||||||
|
Loading…
Reference in New Issue
Block a user