mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
Support returning any http_body::Body from IntoResponse (#86)
Adds associated `Body` and `BodyError` types to `IntoResponse`. This is required for returning responses with bodies other than `hyper::Body` from handlers. That wasn't previously possible. This is a breaking change so should be shipped in 0.2.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use super::{FromRequest, RequestParts};
|
||||
use crate::response::IntoResponse;
|
||||
use crate::{
|
||||
body::{box_body, BoxBody},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use http::Response;
|
||||
use std::convert::Infallible;
|
||||
@@ -29,11 +32,11 @@ macro_rules! impl_from_request {
|
||||
$( $tail: FromRequest<B> + Send, )*
|
||||
B: Send,
|
||||
{
|
||||
type Rejection = Response<crate::body::Body>;
|
||||
type Rejection = Response<BoxBody>;
|
||||
|
||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||
let $head = $head::from_request(req).await.map_err(IntoResponse::into_response)?;
|
||||
$( let $tail = $tail::from_request(req).await.map_err(IntoResponse::into_response)?; )*
|
||||
let $head = $head::from_request(req).await.map_err(|err| err.into_response().map(box_body))?;
|
||||
$( let $tail = $tail::from_request(req).await.map_err(|err| err.into_response().map(box_body))?; )*
|
||||
Ok(($head, $($tail,)*))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user