1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-17 21:56:38 +00:00

Automatically use no_chunking if user specifies stream size

This commit is contained in:
Yinuo Deng 2023-04-14 23:32:45 +08:00
parent c76056bc7e
commit f70c36eff0
No known key found for this signature in database
GPG key ID: 6DF6E347982C88F8

View file

@ -334,6 +334,27 @@ impl HttpResponseBuilder {
self.insert_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM));
}
let contains_length = if let Some(parts) = self.inner() {
parts.headers.contains_key(header::CONTENT_LENGTH)
} else {
false
};
if contains_length {
// Since contains_length is true, these two lines will not panic
let parts = self.inner().unwrap();
let length = parts.headers.get(header::CONTENT_LENGTH).unwrap().to_str();
if let Ok(length) = length { // length is now of type &str
if let Ok(length) = length.parse::<u64>() { //length is now of type u64
// Set no_chunking
// Since no_chuking() uses insert_header(),
// this will not lead to duplicated header even if it exists
self.no_chunking(length);
}
}
}
self.body(BodyStream::new(stream))
}