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 <david.pdrsn@gmail.com>
This commit is contained in:
Marcus Griep 2022-04-29 11:52:21 -04:00 committed by GitHub
parent 5bb924b3a2
commit 6e1835074c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -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)

View file

@ -404,6 +404,27 @@ where
}
}
impl<R> 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<R> 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)]