Skip to content

Commit

Permalink
Merge branch 'master' of github.com:actix/actix-web
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Oct 8, 2018
2 parents 03d988b + 10678a2 commit 07f6ca4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/httpresponse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
44 changes: 44 additions & 0 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 07f6ca4

Please sign in to comment.