mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
Remove the associated Body type on IntoResponse (#571)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
body::{boxed, BoxBody},
|
||||
body::BoxBody,
|
||||
extract::{
|
||||
rejection::{ExtensionRejection, ExtensionsAlreadyExtracted},
|
||||
Extension, FromRequest, RequestParts,
|
||||
@@ -30,7 +30,7 @@ use std::{
|
||||
/// use axum::{
|
||||
/// async_trait,
|
||||
/// extract::{FromRequest, RequestParts},
|
||||
/// body::{self, BoxBody},
|
||||
/// body::BoxBody,
|
||||
/// response::IntoResponse,
|
||||
/// http::{StatusCode, Response},
|
||||
/// };
|
||||
@@ -67,7 +67,7 @@ use std::{
|
||||
/// // once, in case other extractors for the same request also loads the session
|
||||
/// let session: Session = Cached::<Session>::from_request(req)
|
||||
/// .await
|
||||
/// .map_err(|err| err.into_response().map(body::boxed))?
|
||||
/// .map_err(|err| err.into_response())?
|
||||
/// .0;
|
||||
///
|
||||
/// // load user from session...
|
||||
@@ -157,13 +157,10 @@ impl<R> IntoResponse for CachedRejection<R>
|
||||
where
|
||||
R: IntoResponse,
|
||||
{
|
||||
type Body = BoxBody;
|
||||
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
|
||||
|
||||
fn into_response(self) -> Response<Self::Body> {
|
||||
fn into_response(self) -> Response<BoxBody> {
|
||||
match self {
|
||||
Self::ExtensionsAlreadyExtracted(inner) => inner.into_response().map(boxed),
|
||||
Self::Inner(inner) => inner.into_response().map(boxed),
|
||||
Self::ExtensionsAlreadyExtracted(inner) => inner.into_response(),
|
||||
Self::Inner(inner) => inner.into_response(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::convert::Infallible;
|
||||
|
||||
use axum::{
|
||||
body::{Bytes, Full},
|
||||
body::{self, BoxBody, Full},
|
||||
http::{header, HeaderValue, Response, StatusCode},
|
||||
response::IntoResponse,
|
||||
};
|
||||
@@ -41,22 +39,19 @@ impl ErasedJson {
|
||||
}
|
||||
|
||||
impl IntoResponse for ErasedJson {
|
||||
type Body = Full<Bytes>;
|
||||
type BodyError = Infallible;
|
||||
|
||||
fn into_response(self) -> Response<Self::Body> {
|
||||
fn into_response(self) -> Response<BoxBody> {
|
||||
let bytes = match self.0 {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header(header::CONTENT_TYPE, mime::TEXT_PLAIN_UTF_8.as_ref())
|
||||
.body(Full::from(err.to_string()))
|
||||
.body(body::boxed(Full::from(err.to_string())))
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
|
||||
let mut res = Response::new(Full::from(bytes));
|
||||
let mut res = Response::new(body::boxed(Full::from(bytes)));
|
||||
res.headers_mut().insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static(mime::APPLICATION_JSON.as_ref()),
|
||||
|
||||
Reference in New Issue
Block a user