mirror of
https://github.com/actix/actix-web.git
synced 2025-01-07 07:45:29 +00:00
Automatically use no_chunking if user specifies stream size
This commit is contained in:
parent
c76056bc7e
commit
f70c36eff0
1 changed files with 21 additions and 0 deletions
|
@ -334,6 +334,27 @@ impl HttpResponseBuilder {
|
||||||
self.insert_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM));
|
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))
|
self.body(BodyStream::new(stream))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue