From 91c2bbf80468c12d0663330cff185f1d7680c91e Mon Sep 17 00:00:00 2001 From: Bjørn Madsen Date: Wed, 29 Jan 2020 09:32:39 +0100 Subject: Add support for warp --- askama_warp/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 askama_warp/src/lib.rs (limited to 'askama_warp/src/lib.rs') diff --git a/askama_warp/src/lib.rs b/askama_warp/src/lib.rs new file mode 100644 index 0000000..e721ab4 --- /dev/null +++ b/askama_warp/src/lib.rs @@ -0,0 +1,22 @@ +pub use askama::*; +pub use warp; + +use warp::http::{self, header, StatusCode}; +use warp::hyper::Body; +use warp::reply::Response; + +pub fn reply(t: &T, ext: &str) -> Response { + match t.render() { + Ok(body) => http::Response::builder() + .status(StatusCode::OK) + .header( + header::CONTENT_TYPE, + mime::extension_to_mime_type(ext).to_string(), + ) + .body(body.into()), + Err(_) => http::Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::empty()), + } + .unwrap() +} -- cgit