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_actix/src | |
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_actix/src/lib.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/askama_actix/src/lib.rs b/askama_actix/src/lib.rs index c4317c4..59957f4 100644 --- a/askama_actix/src/lib.rs +++ b/askama_actix/src/lib.rs @@ -5,9 +5,9 @@ use std::fmt; use actix_web::body::BoxBody; +use actix_web::http::header::HeaderValue; use actix_web::http::StatusCode; use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError}; -use askama::mime::extension_to_mime_type; pub use askama::*; /// Newtype to let askama::Error implement actix_web::ResponseError. @@ -36,12 +36,9 @@ pub trait TemplateToResponse { impl<T: askama::Template> TemplateToResponse for T { fn to_response(&self) -> HttpResponse<BoxBody> { match self.render() { - Ok(buffer) => { - let ctype = extension_to_mime_type(T::EXTENSION.unwrap_or("txt")); - HttpResponseBuilder::new(StatusCode::OK) - .content_type(ctype) - .body(buffer) - } + Ok(buffer) => HttpResponseBuilder::new(StatusCode::OK) + .content_type(HeaderValue::from_static(T::MIME_TYPE)) + .body(buffer), Err(err) => HttpResponse::from_error(ActixError(err)), } } |