mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-21 00:00:14 +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:
+14
-5
@@ -49,8 +49,11 @@ macro_rules! define_rejection {
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl $crate::response::IntoResponse for $name {
|
||||
fn into_response(self) -> http::Response<$crate::body::Body> {
|
||||
let mut res = http::Response::new($crate::body::Body::from($body));
|
||||
type Body = http_body::Full<bytes::Bytes>;
|
||||
type BodyError = std::convert::Infallible;
|
||||
|
||||
fn into_response(self) -> http::Response<Self::Body> {
|
||||
let mut res = http::Response::new(http_body::Full::from($body));
|
||||
*res.status_mut() = http::StatusCode::$status;
|
||||
res
|
||||
}
|
||||
@@ -77,9 +80,12 @@ macro_rules! define_rejection {
|
||||
}
|
||||
|
||||
impl IntoResponse for $name {
|
||||
fn into_response(self) -> http::Response<Body> {
|
||||
type Body = http_body::Full<bytes::Bytes>;
|
||||
type BodyError = std::convert::Infallible;
|
||||
|
||||
fn into_response(self) -> http::Response<Self::Body> {
|
||||
let mut res =
|
||||
http::Response::new(Body::from(format!(concat!($body, ": {}"), self.0)));
|
||||
http::Response::new(http_body::Full::from(format!(concat!($body, ": {}"), self.0)));
|
||||
*res.status_mut() = http::StatusCode::$status;
|
||||
res
|
||||
}
|
||||
@@ -106,7 +112,10 @@ macro_rules! composite_rejection {
|
||||
}
|
||||
|
||||
impl $crate::response::IntoResponse for $name {
|
||||
fn into_response(self) -> http::Response<$crate::body::Body> {
|
||||
type Body = http_body::Full<bytes::Bytes>;
|
||||
type BodyError = std::convert::Infallible;
|
||||
|
||||
fn into_response(self) -> http::Response<Self::Body> {
|
||||
match self {
|
||||
$(
|
||||
Self::$variant(inner) => inner.into_response(),
|
||||
|
||||
Reference in New Issue
Block a user