From c76056bc7e8afddf3fdabb961a3e549a004c5b17 Mon Sep 17 00:00:00 2001 From: Yinuo Deng Date: Fri, 14 Apr 2023 21:43:31 +0800 Subject: [PATCH] Set mime type for stream response if it is not set by the user --- actix-web/src/response/builder.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/actix-web/src/response/builder.rs b/actix-web/src/response/builder.rs index 120d4c358..c454ee6da 100644 --- a/actix-web/src/response/builder.rs +++ b/actix-web/src/response/builder.rs @@ -323,6 +323,17 @@ impl HttpResponseBuilder { S: Stream> + 'static, E: Into + '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)) }