Skip to content

Commit

Permalink
feat(header): add ContentType::json(), plaintext(), html(), jpeg(), a…
Browse files Browse the repository at this point in the history
…nd png() constructors
  • Loading branch information
seanmonstar committed May 12, 2015
1 parent c2938fb commit b6114ec
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/header/common/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()] });

0 comments on commit b6114ec

Please sign in to comment.