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
+5 -8
View File
@@ -6,7 +6,6 @@
use askama::Template;
use axum::{
body::{self, Full},
extract,
http::StatusCode,
response::{Html, IntoResponse, Response},
@@ -55,13 +54,11 @@ where
fn into_response(self) -> Response {
match self.0.render() {
Ok(html) => Html(html).into_response(),
Err(err) => Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(body::boxed(Full::from(format!(
"Failed to render template. Error: {}",
err
))))
.unwrap(),
Err(err) => (
StatusCode::INTERNAL_SERVER_ERROR,
format!("Failed to render template. Error: {}", err),
)
.into_response(),
}
}
}