From 332d741f212eb2aac7bfb2eec1df1f33bfb46a05 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Thu, 6 Jan 2022 14:30:46 +0100 Subject: Use Template::MIME_TYPE instead of extension --- askama_mendes/src/lib.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'askama_mendes/src/lib.rs') 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( app: &A, req: &Parts, t: &T, - ext: Option<&str>, + _ext: Option<&str>, ) -> Response where A: Application, @@ -29,13 +26,9 @@ where Err(e) => return >::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() } -- cgit