aboutsummaryrefslogtreecommitdiffstats
path: root/askama_axum
diff options
context:
space:
mode:
authorLibravatar Jonas Platte <jplatte+git@posteo.de>2022-03-31 22:40:45 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2022-03-31 23:12:21 +0200
commita9132fd6c78d0cc740686d5acc89267f5fa2fc7b (patch)
tree1b6f544513fdfcc41814bde23c86b6986d28ab01 /askama_axum
parent521834209beefdce1d0cba2a57d5cc8c303267ab (diff)
downloadaskama-a9132fd6c78d0cc740686d5acc89267f5fa2fc7b.tar.gz
askama-a9132fd6c78d0cc740686d5acc89267f5fa2fc7b.tar.bz2
askama-a9132fd6c78d0cc740686d5acc89267f5fa2fc7b.zip
Simplify the implementation of askama_axum
Diffstat (limited to 'askama_axum')
-rw-r--r--askama_axum/Cargo.toml1
-rw-r--r--askama_axum/src/lib.rs25
2 files changed, 9 insertions, 17 deletions
diff --git a/askama_axum/Cargo.toml b/askama_axum/Cargo.toml
index 283fd2a..834daf4 100644
--- a/askama_axum/Cargo.toml
+++ b/askama_axum/Cargo.toml
@@ -16,7 +16,6 @@ readme = "README.md"
askama = { version = "0.11.0", path = "../askama", default-features = false, features = ["with-axum", "mime", "mime_guess"] }
axum-core = "0.2"
http = "0.2"
-http-body = "0.4"
[dev-dependencies]
axum = { version = "0.5", default-features = false }
diff --git a/askama_axum/src/lib.rs b/askama_axum/src/lib.rs
index 1048674..da3d699 100644
--- a/askama_axum/src/lib.rs
+++ b/askama_axum/src/lib.rs
@@ -3,26 +3,19 @@
#![deny(unreachable_pub)]
pub use askama::*;
-use axum_core::body;
-pub use axum_core::body::BoxBody;
-pub use axum_core::response::IntoResponse;
-pub use http::Response;
+pub use axum_core::response::{IntoResponse, Response};
use http::StatusCode;
-use http_body::{Empty, Full};
-pub fn into_response<T: Template>(t: &T, _ext: &str) -> Response<BoxBody> {
+pub fn into_response<T: Template>(t: &T, _ext: &str) -> Response {
match t.render() {
- Ok(body) => Response::builder()
- .status(StatusCode::OK)
- .header(
+ Ok(body) => {
+ let headers = [(
http::header::CONTENT_TYPE,
http::HeaderValue::from_static(T::MIME_TYPE),
- )
- .body(body::boxed(Full::from(body)))
- .unwrap(),
- Err(_) => Response::builder()
- .status(StatusCode::INTERNAL_SERVER_ERROR)
- .body(body::boxed(Empty::new()))
- .unwrap(),
+ )];
+
+ (headers, body).into_response()
+ }
+ Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
}
}