1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-01-18 13:15:27 +00:00

Set mime type for stream response if it is not set by the user

This commit is contained in:
Yinuo Deng 2023-04-14 21:43:31 +08:00
parent e81dc768dc
commit c76056bc7e
No known key found for this signature in database
GPG key ID: 6DF6E347982C88F8

View file

@ -323,6 +323,17 @@ impl HttpResponseBuilder {
S: Stream<Item = Result<Bytes, E>> + '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))
}