blob: 725c56f64fd0435f6f7e9e26f9ce74f6b4b8c006 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#![deny(elided_lifetimes_in_paths)]
#![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;
use http::StatusCode;
use http_body::{Empty, Full};
pub fn into_response<T: Template>(t: &T, ext: &str) -> Response<BoxBody> {
match t.render() {
Ok(body) => Response::builder()
.status(StatusCode::OK)
.header(
"content-type",
askama::mime::extension_to_mime_type(ext).to_string(),
)
.body(body::boxed(Full::from(body)))
.unwrap(),
Err(_) => Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(body::boxed(Empty::new()))
.unwrap(),
}
}
|