From 7ae5a43877966cb335a1a03b128f7cc6caefac51 Mon Sep 17 00:00:00 2001 From: lzx <40080252+lzxZz@users.noreply.github.com> Date: Sat, 6 Oct 2018 13:16:12 +0800 Subject: [PATCH 1/2] httpresponse.rs doc fix (#534) --- src/httpresponse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 59815c58..8b091d42 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -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 } From 10678a22af6a138a6106ffc3dccd281625bf7c4b Mon Sep 17 00:00:00 2001 From: Danil Berestov Date: Sat, 6 Oct 2018 13:17:20 +0800 Subject: [PATCH 2/2] test content length (#532) --- tests/test_server.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_server.rs b/tests/test_server.rs index 477d3e64..cb19cfed 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -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)); + } +} +