diff options
Diffstat (limited to 'askama_mendes')
-rw-r--r-- | askama_mendes/src/lib.rs | 19 | ||||
-rw-r--r-- | askama_mendes/tests/basic.rs | 2 |
2 files changed, 7 insertions, 14 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() } 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!"[..]); } |