Skip to content

Commit b6114ec

Browse files
committed
feat(header): add ContentType::json(), plaintext(), html(), jpeg(), and png() constructors
1 parent c2938fb commit b6114ec

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/header/common/content_type.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,30 @@ header! {
3434
}
3535
}
3636

37+
impl ContentType {
38+
/// A constructor to easily create a `Content-Type: application/json; charset=utf-8` header.
39+
pub fn json() -> ContentType {
40+
ContentType(mime!(Application/Json; Charset=Utf8))
41+
}
42+
43+
/// A constructor to easily create a `Content-Type: text/plain; charset=utf-8` header.
44+
pub fn plaintext() -> ContentType {
45+
ContentType(mime!(Text/Plain; Charset=Utf8))
46+
}
47+
48+
/// A constructor to easily create a `Content-Type: text/html; charset=utf-8` header.
49+
pub fn html() -> ContentType {
50+
ContentType(mime!(Text/Html; Charset=Utf8))
51+
}
52+
53+
/// A constructor to easily create a `Content-Type: image/jpeg` header.
54+
pub fn jpeg() -> ContentType {
55+
ContentType(mime!(Image/Jpeg))
56+
}
57+
58+
/// A constructor to easily create a `Content-Type: image/png` header.
59+
pub fn png() -> ContentType {
60+
ContentType(mime!(Image/Png))
61+
}
62+
}
3763
bench_header!(bench, ContentType, { vec![b"application/json; charset=utf-8".to_vec()] });

0 commit comments

Comments
 (0)