Merge pull request #522 from hyperium/header-convenient-constructors

Header convenient constructors
This commit is contained in:
Sean McArthur
2015-05-11 20:22:18 -07:00
5 changed files with 46 additions and 8 deletions

View File

@@ -71,6 +71,18 @@ header! {
}
}
impl Connection {
/// A constructor to easily create a `Connection: close` header.
pub fn close() -> Connection {
Connection(vec![ConnectionOption::Close])
}
/// A constructor to easily create a `Connection: keep-alive` header.
pub fn keep_alive() -> Connection {
Connection(vec![ConnectionOption::KeepAlive])
}
}
bench_header!(close, Connection, { vec![b"close".to_vec()] });
bench_header!(keep_alive, Connection, { vec![b"keep-alive".to_vec()] });
bench_header!(header, Connection, { vec![b"authorization".to_vec()] });

View File

@@ -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()] });