mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 09:42:40 +01:00
add content-length test
This commit is contained in:
parent
25af82c45a
commit
dda5b399ca
@ -8,10 +8,10 @@ use std::{io::Read, io::Write, net, thread, time};
|
|||||||
|
|
||||||
use actix::System;
|
use actix::System;
|
||||||
use actix_net::server::Server;
|
use actix_net::server::Server;
|
||||||
use actix_web::{client, test};
|
use actix_web::{client, test, HttpMessage};
|
||||||
use futures::future;
|
use futures::future;
|
||||||
|
|
||||||
use actix_http::{h1, Error, KeepAlive, Response, ServiceConfig};
|
use actix_http::{h1, Error, KeepAlive, Request, Response, ServiceConfig};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_h1_v2() {
|
fn test_h1_v2() {
|
||||||
@ -88,3 +88,57 @@ fn test_malformed_request() {
|
|||||||
let _ = stream.read_to_string(&mut data);
|
let _ = stream.read_to_string(&mut data);
|
||||||
assert!(data.starts_with("HTTP/1.1 400 Bad Request"));
|
assert!(data.starts_with("HTTP/1.1 400 Bad Request"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_content_length() {
|
||||||
|
use actix_http::http::{
|
||||||
|
header::{HeaderName, HeaderValue},
|
||||||
|
StatusCode,
|
||||||
|
};
|
||||||
|
|
||||||
|
let addr = test::TestServer::unused_addr();
|
||||||
|
thread::spawn(move || {
|
||||||
|
Server::new()
|
||||||
|
.bind("test", addr, move || {
|
||||||
|
let settings = ServiceConfig::build().client_timeout(100).finish();
|
||||||
|
h1::H1Service::new(settings, |req: Request| {
|
||||||
|
let indx: usize = req.uri().path()[1..].parse().unwrap();
|
||||||
|
let statuses = [
|
||||||
|
StatusCode::NO_CONTENT,
|
||||||
|
StatusCode::CONTINUE,
|
||||||
|
StatusCode::SWITCHING_PROTOCOLS,
|
||||||
|
StatusCode::PROCESSING,
|
||||||
|
StatusCode::OK,
|
||||||
|
StatusCode::NOT_FOUND,
|
||||||
|
];
|
||||||
|
future::ok::<_, Error>(Response::new(statuses[indx]))
|
||||||
|
})
|
||||||
|
}).unwrap()
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
thread::sleep(time::Duration::from_millis(100));
|
||||||
|
|
||||||
|
let header = HeaderName::from_static("content-length");
|
||||||
|
let value = HeaderValue::from_static("0");
|
||||||
|
|
||||||
|
let mut sys = System::new("test");
|
||||||
|
{
|
||||||
|
for i in 0..4 {
|
||||||
|
let req =
|
||||||
|
client::ClientRequest::get(format!("http://{}/{}", addr, i).as_str())
|
||||||
|
.finish()
|
||||||
|
.unwrap();
|
||||||
|
let response = sys.block_on(req.send()).unwrap();
|
||||||
|
assert_eq!(response.headers().get(&header), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 4..6 {
|
||||||
|
let req =
|
||||||
|
client::ClientRequest::get(format!("http://{}/{}", addr, i).as_str())
|
||||||
|
.finish()
|
||||||
|
.unwrap();
|
||||||
|
let response = sys.block_on(req.send()).unwrap();
|
||||||
|
assert_eq!(response.headers().get(&header), Some(&value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user