explicitly set content-type to text/html; charset=utf-8

master
Edward Shen 2020-04-17 13:23:00 -04:00
parent 8cdd216b39
commit 9cf01f5991
Signed by: edward
GPG Key ID: 19182661E818369F
2 changed files with 26 additions and 19 deletions

View File

@ -4,7 +4,7 @@ use crate::config::{read_config, Route, RouteGroup};
use actix_web::{middleware::Logger, App, HttpServer};
use clap::{crate_authors, crate_version, load_yaml, App as ClapApp};
use error::BunBunError;
use handlebars::{Handlebars};
use handlebars::Handlebars;
use hotwatch::{Event, Hotwatch};
use log::{debug, info, trace, warn};
use std::cmp::min;
@ -118,7 +118,9 @@ fn cache_routes(groups: &[RouteGroup]) -> HashMap<String, Route> {
fn compile_templates() -> Handlebars {
let mut handlebars = Handlebars::new();
handlebars.set_strict_mode(true);
handlebars.register_partial("bunbun_version", env!("CARGO_PKG_VERSION")).unwrap();
handlebars
.register_partial("bunbun_version", env!("CARGO_PKG_VERSION"))
.unwrap();
macro_rules! register_template {
[ $( $template:expr ),* ] => {
$(

View File

@ -1,4 +1,5 @@
use crate::{template_args, BunBunError, Route, State};
use actix_web::http::header::ContentType;
use actix_web::web::{Data, Query};
use actix_web::{get, http::header};
use actix_web::{HttpRequest, HttpResponse, Responder};
@ -26,16 +27,18 @@ type StateData = Data<Arc<RwLock<State>>>;
#[get("/")]
pub async fn index(data: StateData, req: HttpRequest) -> impl Responder {
let data = data.read().unwrap();
HttpResponse::Ok().body(
req
.app_data::<Handlebars>()
.unwrap()
.render(
"index",
&template_args::hostname(data.public_address.clone()),
)
.unwrap(),
)
HttpResponse::Ok()
.set_header(header::CONTENT_TYPE, "text/html; charset=utf-8")
.body(
req
.app_data::<Handlebars>()
.unwrap()
.render(
"index",
&template_args::hostname(data.public_address.clone()),
)
.unwrap(),
)
}
#[get("/bunbunsearch.xml")]
@ -61,13 +64,15 @@ pub async fn opensearch(data: StateData, req: HttpRequest) -> impl Responder {
#[get("/ls")]
pub async fn list(data: StateData, req: HttpRequest) -> impl Responder {
let data = data.read().unwrap();
HttpResponse::Ok().body(
req
.app_data::<Handlebars>()
.unwrap()
.render("list", &data.groups)
.unwrap(),
)
HttpResponse::Ok()
.set_header(header::CONTENT_TYPE, "text/html; charset=utf-8")
.body(
req
.app_data::<Handlebars>()
.unwrap()
.render("list", &data.groups)
.unwrap(),
)
}
#[derive(Deserialize)]