Add setting of Content-Length to the no_chunking function

This commit is contained in:
Omid Rad 2020-05-08 12:11:46 +02:00
parent b7649af2a2
commit 0b51f4584c
2 changed files with 4 additions and 2 deletions

View File

@ -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);
}

View File

@ -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))
})))
});