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

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

This commit is contained in:
Nikolay Kim 2018-10-08 13:06:49 -07:00
commit 07f6ca4b71
2 changed files with 45 additions and 1 deletions

View File

@ -272,7 +272,7 @@ impl HttpResponse {
self.get_mut().response_size = size;
}
/// Set write buffer capacity
/// Get write buffer capacity
pub fn write_buffer_capacity(&self) -> usize {
self.get_ref().write_capacity
}

View File

@ -1355,3 +1355,47 @@ fn test_ssl_handshake_timeout() {
let _ = sys.stop();
}
#[test]
fn test_content_length() {
use http::StatusCode;
use actix_web::http::header::{HeaderName, HeaderValue};
let mut srv = test::TestServer::new(move |app| {
app.resource("/{status}", |r| {
r.f(|req: &HttpRequest| {
let indx: usize =
req.match_info().get("status").unwrap().parse().unwrap();
let statuses = [
StatusCode::NO_CONTENT,
StatusCode::CONTINUE,
StatusCode::SWITCHING_PROTOCOLS,
StatusCode::PROCESSING,
StatusCode::OK,
StatusCode::NOT_FOUND,
];
HttpResponse::new(statuses[indx])
})
});
});
let addr = srv.addr();
let mut get_resp = |i| {
let url = format!("http://{}/{}", addr, i);
let req = srv.get().uri(url).finish().unwrap();
srv.execute(req.send()).unwrap()
};
let header = HeaderName::from_static("content-length");
let value = HeaderValue::from_static("0");
for i in 0..4 {
let response = get_resp(i);
assert_eq!(response.headers().get(&header), None);
}
for i in 4..6 {
let response = get_resp(i);
assert_eq!(response.headers().get(&header), Some(&value));
}
}