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:
David Pedersen
2022-02-28 23:04:33 +00:00
committed by GitHub
co-authored by Jonas Platte
parent da74084146
commit f12ab072c5
23 changed files with 1117 additions and 930 deletions
+2 -5
View File
@@ -4,12 +4,11 @@
mod de;
use crate::{
body::{boxed, Full},
extract::{rejection::*, FromRequest, RequestParts},
response::{IntoResponse, Response},
routing::{InvalidUtf8InPathParam, UrlParams},
};
use async_trait::async_trait;
use axum_core::response::{IntoResponse, Response};
use http::StatusCode;
use serde::de::DeserializeOwned;
use std::{
@@ -382,9 +381,7 @@ impl IntoResponse for FailedToDeserializePathParams {
(StatusCode::INTERNAL_SERVER_ERROR, self.0.kind.to_string())
}
};
let mut res = Response::new(boxed(Full::from(body)));
*res.status_mut() = status;
res
(status, body).into_response()
}
}