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_actix/src/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'askama_actix') 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 TemplateToResponse for T { fn to_response(&self) -> HttpResponse { 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)), } } -- cgit