From 0b51f4584c5b59ba10200141a08dd4442deeac8a Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Fri, 8 May 2020 12:11:46 +0200 Subject: [PATCH] Add setting of Content-Length to the no_chunking function --- actix-http/src/response.rs | 4 +++- tests/test_server.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index ac7f86fe7..9086212f1 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -472,7 +472,9 @@ impl ResponseBuilder { /// Disable chunked transfer encoding for HTTP/1.1 streaming responses. #[inline] - pub fn no_chunking(&mut self) -> &mut Self { + pub fn no_chunking(&mut self, len: u64) -> &mut Self { + self.header(header::CONTENT_LENGTH, len); + if let Some(parts) = parts(&mut self.head, &self.err) { parts.no_chunking(true); } diff --git a/tests/test_server.rs b/tests/test_server.rs index 8c0d3dcce..a4dfa65a0 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -371,7 +371,7 @@ async fn test_no_chunking() { let srv = test::start_with(test::config().h1(), || { App::new().service(web::resource("/").route(web::to(move || { HttpResponse::Ok() - .no_chunking() + .no_chunking(STR.len() as u64) .streaming(TestBody::new(Bytes::from_static(STR.as_ref()), 24)) }))) });