mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Add IntoResponseParts (#797)
* Add `IntoResponseParts` * docs * Add test * don't allow overriding body or response * macroify impls * re-order things a bit * Fix tests * Also allow overriding version * Move things into separate modules * docs * clean up * fix trybuild test * remove churn * simplify buliding response * fixup test * fix docs typo * Use `HeaderValue::from_static`, might be faster * Bring back `impl IntoResponse` in example * Remove blanket impl to improve error message * don't need to set `content-type` * Apply suggestions from code review Co-authored-by: Jonas Platte <[email protected]> * changelog Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
co-authored by
Jonas Platte
parent
da74084146
commit
f12ab072c5
@@ -1,8 +1,7 @@
|
||||
//! Rejection response types.
|
||||
|
||||
use crate::body;
|
||||
use http::{Response, StatusCode};
|
||||
use http_body::Full;
|
||||
use crate::response::{IntoResponse, Response};
|
||||
use http::StatusCode;
|
||||
use std::fmt;
|
||||
|
||||
/// Rejection type used if you try and extract the request body more than
|
||||
@@ -15,11 +14,9 @@ impl BodyAlreadyExtracted {
|
||||
const BODY: &'static str = "Cannot have two request body extractors for a single handler";
|
||||
}
|
||||
|
||||
impl crate::response::IntoResponse for BodyAlreadyExtracted {
|
||||
fn into_response(self) -> crate::response::Response {
|
||||
let mut res = Response::new(body::boxed(Full::from(Self::BODY)));
|
||||
*res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
res
|
||||
impl IntoResponse for BodyAlreadyExtracted {
|
||||
fn into_response(self) -> Response {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, Self::BODY).into_response()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user