diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-01-06 14:30:46 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-01-07 13:18:03 +0100 |
commit | 332d741f212eb2aac7bfb2eec1df1f33bfb46a05 (patch) | |
tree | f7f2d529d3db59beae9e28db8c3938e37d6a8f20 /askama_mendes/src/lib.rs | |
parent | a9aebf82fbb59a0323c78c4c248eaaafab1ab00f (diff) | |
download | askama-332d741f212eb2aac7bfb2eec1df1f33bfb46a05.tar.gz askama-332d741f212eb2aac7bfb2eec1df1f33bfb46a05.tar.bz2 askama-332d741f212eb2aac7bfb2eec1df1f33bfb46a05.zip |
Use Template::MIME_TYPE instead of extension
Diffstat (limited to '')
-rw-r--r-- | askama_mendes/src/lib.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/askama_mendes/src/lib.rs b/askama_mendes/src/lib.rs index baaa49f..d1ccb2c 100644 --- a/askama_mendes/src/lib.rs +++ b/askama_mendes/src/lib.rs @@ -2,13 +2,10 @@ #![deny(elided_lifetimes_in_paths)] #![deny(unreachable_pub)] -use std::convert::TryFrom; - use mendes::application::{Application, Responder}; use mendes::http::header::{HeaderValue, CONTENT_LENGTH, CONTENT_TYPE}; use mendes::http::request::Parts; use mendes::http::Response; -use mime_guess::MimeGuess; pub use askama::*; @@ -16,7 +13,7 @@ pub fn into_response<A, T>( app: &A, req: &Parts, t: &T, - ext: Option<&str>, + _ext: Option<&str>, ) -> Response<A::ResponseBody> where A: Application, @@ -29,13 +26,9 @@ where Err(e) => return <A::Error as From<_>>::from(e).into_response(app, req), }; - let mut builder = Response::builder(); - builder = builder.header(CONTENT_LENGTH, content.len()); - if let Some(ext) = ext { - if let Some(ty) = MimeGuess::from_ext(ext).first() { - builder = builder.header(CONTENT_TYPE, HeaderValue::try_from(ty.as_ref()).unwrap()); - } - } - - builder.body(content.into()).unwrap() + Response::builder() + .header(CONTENT_LENGTH, content.len()) + .header(CONTENT_TYPE, HeaderValue::from_static(T::MIME_TYPE)) + .body(content.into()) + .unwrap() } |