From 4b1a24b56f44af85fb02c2a6b7cc5971412f5725 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 4 Feb 2022 19:16:04 +0000 Subject: [PATCH] implement responder for byte vec --- actix-http/CHANGES.md | 5 ++++- actix-http/src/responses/response.rs | 18 ++++++++++++++++++ actix-web/CHANGES.md | 3 +++ actix-web/src/response/responder.rs | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index afc988d43..0585f4f20 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,14 +1,17 @@ # Changes ## Unreleased - 2021-xx-xx +### Added +- Implement `From>` for `Response>`. [#????] + ### Changed - `error::DispatcherError` enum is now marked `#[non_exhaustive]`. [#2624] - ### Fixed - Issue where handlers that took payload but then dropped without reading it to EOF it would cause keep-alive connections to become stuck. [#2624] [#2624]: https://github.com/actix/actix-web/pull/2624 +[#????]: https://github.com/actix/actix-web/pull/???? ## 3.0.0-rc.1 - 2022-01-31 diff --git a/actix-http/src/responses/response.rs b/actix-http/src/responses/response.rs index da5503c1c..ceb158f65 100644 --- a/actix-http/src/responses/response.rs +++ b/actix-http/src/responses/response.rs @@ -285,6 +285,24 @@ impl From<&'static [u8]> for Response<&'static [u8]> { } } +impl From> for Response> { + fn from(val: Vec) -> Self { + let mut res = Response::with_body(StatusCode::OK, val); + let mime = mime::APPLICATION_OCTET_STREAM.try_into_value().unwrap(); + res.headers_mut().insert(header::CONTENT_TYPE, mime); + res + } +} + +impl From<&Vec> for Response> { + fn from(val: &Vec) -> Self { + let mut res = Response::with_body(StatusCode::OK, val.clone()); + let mime = mime::APPLICATION_OCTET_STREAM.try_into_value().unwrap(); + res.headers_mut().insert(header::CONTENT_TYPE, mime); + res + } +} + impl From for Response { fn from(val: String) -> Self { let mut res = Response::with_body(StatusCode::OK, val); diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 7ce282c8b..168888bb3 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,7 +1,10 @@ # Changes ## Unreleased - 2021-xx-xx +### Added +- Implement `Responder` for `Vec`. [#????] +[#????]: https://github.com/actix/actix-web/pull/???? ## 4.0.0-rc.2 - 2022-02-02 ### Added diff --git a/actix-web/src/response/responder.rs b/actix-web/src/response/responder.rs index d1b9e49e0..cb71369cf 100644 --- a/actix-web/src/response/responder.rs +++ b/actix-web/src/response/responder.rs @@ -132,6 +132,7 @@ macro_rules! impl_responder_by_forward_into_base_response { } impl_responder_by_forward_into_base_response!(&'static [u8]); +impl_responder_by_forward_into_base_response!(Vec); impl_responder_by_forward_into_base_response!(Bytes); impl_responder_by_forward_into_base_response!(BytesMut);