From 8f216fed4c51f470777a004317ecc09869728fb7 Mon Sep 17 00:00:00 2001 From: Hajime Fukuda Date: Wed, 17 Jan 2018 22:49:27 +0900 Subject: infer Content-type from the file extension for iron integration --- askama_shared/src/generator.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'askama_shared/src/generator.rs') diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index e4eb9ec..173ecbf 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -251,6 +251,15 @@ impl<'a> Generator<'a> { self.write_header(state, "::askama::iron::Modifier<::askama::iron::Response>", &[]); self.writeln("fn modify(self, res: &mut ::askama::iron::Response) {"); self.writeln("res.body = Some(Box::new(self.render().unwrap().into_bytes()));"); + + let ext = state.input.path.extension().map_or("", |s| s.to_str().unwrap_or("")); + match ext { + "html" | "htm" => { + self.writeln("::askama::iron::ContentType::html().0.modify(res);"); + }, + _ => (), + }; + self.writeln("}"); self.writeln("}"); } -- cgit