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 ++++++------------- askama_mendes/tests/basic.rs | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'askama_mendes') 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() } diff --git a/askama_mendes/tests/basic.rs b/askama_mendes/tests/basic.rs index 2a07c13..e2f5b25 100644 --- a/askama_mendes/tests/basic.rs +++ b/askama_mendes/tests/basic.rs @@ -19,7 +19,7 @@ async fn test() { rsp.headers .get("content-type") .and_then(|hv| hv.to_str().ok()), - Some("text/plain") + Some("text/plain; charset=utf-8") ); assert_eq!(to_bytes(body).await.unwrap(), &b"Hello, world!"[..]); } -- cgit