mirror of
https://github.com/actix/actix-web.git
synced 2025-03-28 05:45:27 +00:00
Set mime type for stream response if it is not set by the user
This commit is contained in:
parent
e81dc768dc
commit
c76056bc7e
1 changed files with 11 additions and 0 deletions
|
@ -323,6 +323,17 @@ impl HttpResponseBuilder {
|
||||||
S: Stream<Item = Result<Bytes, E>> + 'static,
|
S: Stream<Item = Result<Bytes, E>> + 'static,
|
||||||
E: Into<BoxError> + 'static,
|
E: Into<BoxError> + 'static,
|
||||||
{
|
{
|
||||||
|
// Set mime type to application/octet-stream if it is not set
|
||||||
|
let contains_mime = if let Some(parts) = self.inner() {
|
||||||
|
parts.headers.contains_key(header::CONTENT_TYPE)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
if !contains_mime {
|
||||||
|
self.insert_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM));
|
||||||
|
}
|
||||||
|
|
||||||
self.body(BodyStream::new(stream))
|
self.body(BodyStream::new(stream))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue