diff options
author | Hajime Fukuda <hajime.fukuda@me.com> | 2018-01-17 22:49:27 +0900 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-01-19 12:48:17 +0100 |
commit | 8f216fed4c51f470777a004317ecc09869728fb7 (patch) | |
tree | 286114e076ab2f835b6b81c0128b7bc52a1b912e /askama_shared/src | |
parent | f376d96ee1bab82cf1cbb32fbdc0dbf969e5df9c (diff) | |
download | askama-8f216fed4c51f470777a004317ecc09869728fb7.tar.gz askama-8f216fed4c51f470777a004317ecc09869728fb7.tar.bz2 askama-8f216fed4c51f470777a004317ecc09869728fb7.zip |
infer Content-type from the file extension for iron integration
Diffstat (limited to 'askama_shared/src')
-rw-r--r-- | askama_shared/src/generator.rs | 9 |
1 files changed, 9 insertions, 0 deletions
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("}"); } |