From 6e1835074c1dd3e1beb631c87cf0096c8624fa6f Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Fri, 29 Apr 2022 11:52:21 -0400 Subject: [PATCH] Implement `IntoResponse` for `Response<()>` and `response::Parts` (#950) * feat(axum-core): add IntoResponse for `http::response` types * chore: narrow impl to `Response<()>` * include extensions * changelog Co-authored-by: David Pedersen --- axum-core/CHANGELOG.md | 3 +++ axum-core/src/response/into_response.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md index 276f70a0..268c504d 100644 --- a/axum-core/CHANGELOG.md +++ b/axum-core/CHANGELOG.md @@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased - **added:** Implement `IntoResponse` and `IntoResponseParts` for `http::Extensions` ([#975]) +- **added:** Implement `IntoResponse` for `(http::response::Parts, impl IntoResponse)` ([#950]) +- **added:** Implement `IntoResponse` for `(http::response::Response<()>, impl IntoResponse)` ([#950]) +[#950]: https://github.com/tokio-rs/axum/pull/950 [#975]: https://github.com/tokio-rs/axum/pull/975 # 0.2.3 (25. April, 2022) diff --git a/axum-core/src/response/into_response.rs b/axum-core/src/response/into_response.rs index e14936bb..23beaa5f 100644 --- a/axum-core/src/response/into_response.rs +++ b/axum-core/src/response/into_response.rs @@ -404,6 +404,27 @@ where } } +impl IntoResponse for (http::response::Parts, R) +where + R: IntoResponse, +{ + fn into_response(self) -> Response { + let (parts, res) = self; + (parts.status, parts.headers, parts.extensions, res).into_response() + } +} + +impl IntoResponse for (http::response::Response<()>, R) +where + R: IntoResponse, +{ + fn into_response(self) -> Response { + let (template, res) = self; + let (parts, ()) = template.into_parts(); + (parts, res).into_response() + } +} + macro_rules! impl_into_response { ( $($ty:ident),* $(,)? ) => { #[allow(non_snake_case)]