mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Implement IntoResponse and IntoResponseParts for http::Extensions (#975)
* Implement `IntoResponse` and `IntoResponseParts` for `http::Extensions` Requires a new release of `http`. * remove http patch * changelog ref
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::{body, BoxError};
|
||||
use bytes::{buf::Chain, Buf, Bytes, BytesMut};
|
||||
use http::{
|
||||
header::{self, HeaderMap, HeaderName, HeaderValue},
|
||||
StatusCode,
|
||||
Extensions, StatusCode,
|
||||
};
|
||||
use http_body::{
|
||||
combinators::{MapData, MapErr},
|
||||
@@ -384,6 +384,14 @@ impl IntoResponse for HeaderMap {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for Extensions {
|
||||
fn into_response(self) -> Response {
|
||||
let mut res = ().into_response();
|
||||
*res.extensions_mut() = self;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, const N: usize> IntoResponse for [(K, V); N]
|
||||
where
|
||||
K: TryInto<HeaderName>,
|
||||
|
||||
@@ -249,3 +249,12 @@ macro_rules! impl_into_response_parts {
|
||||
}
|
||||
|
||||
all_the_tuples!(impl_into_response_parts);
|
||||
|
||||
impl IntoResponseParts for Extensions {
|
||||
type Error = Infallible;
|
||||
|
||||
fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
|
||||
res.extensions_mut().extend(self);
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user