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 --- testing/tests/iron.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'testing/tests/iron.rs') diff --git a/testing/tests/iron.rs b/testing/tests/iron.rs index 6f8868f..95c366c 100644 --- a/testing/tests/iron.rs +++ b/testing/tests/iron.rs @@ -11,10 +11,30 @@ struct HelloTemplate<'a> { name: &'a str, } +#[derive(Template)] +#[template(path = "hello.txt")] +struct HelloTextTemplate<'a> { + name: &'a str, +} + #[test] fn test_iron() { let rsp = Response::with((status::Ok, HelloTemplate { name: "world" })); let mut buf = Vec::new(); let _ = rsp.body.unwrap().write_body(&mut buf); assert_eq!(buf, b"Hello, world!"); + + let content_type = rsp.headers.get::().unwrap(); + assert_eq!(format!("{}", content_type), "text/html; charset=utf-8"); +} + +#[test] +fn test_iron_non_html() { + let rsp = Response::with((status::Ok, HelloTextTemplate { name: "world" })); + let mut buf = Vec::new(); + let _ = rsp.body.unwrap().write_body(&mut buf); + assert_eq!(buf, b"Hello, world!"); + + let content_type = rsp.headers.get::(); + assert_eq!(content_type, None); } -- cgit