From b6114ecd2e65bd59e79a67a45913adaf0f1552f0 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 11 May 2015 18:49:19 -0700 Subject: [PATCH] feat(header): add ContentType::json(), plaintext(), html(), jpeg(), and png() constructors --- src/header/common/content_type.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/header/common/content_type.rs b/src/header/common/content_type.rs index d88273595b..1d9e284178 100644 --- a/src/header/common/content_type.rs +++ b/src/header/common/content_type.rs @@ -34,4 +34,30 @@ header! { } } +impl ContentType { + /// A constructor to easily create a `Content-Type: application/json; charset=utf-8` header. + pub fn json() -> ContentType { + ContentType(mime!(Application/Json; Charset=Utf8)) + } + + /// A constructor to easily create a `Content-Type: text/plain; charset=utf-8` header. + pub fn plaintext() -> ContentType { + ContentType(mime!(Text/Plain; Charset=Utf8)) + } + + /// A constructor to easily create a `Content-Type: text/html; charset=utf-8` header. + pub fn html() -> ContentType { + ContentType(mime!(Text/Html; Charset=Utf8)) + } + + /// A constructor to easily create a `Content-Type: image/jpeg` header. + pub fn jpeg() -> ContentType { + ContentType(mime!(Image/Jpeg)) + } + + /// A constructor to easily create a `Content-Type: image/png` header. + pub fn png() -> ContentType { + ContentType(mime!(Image/Png)) + } +} bench_header!(bench, ContentType, { vec![b"application/json; charset=utf-8".to_vec()] });