From bdc19d52bf5ec2e63b785de31bfe0ad3ba4d2550 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 10 Dec 2016 12:19:41 -0800 Subject: [PATCH] feat(headers): add star, json, text, image constructors to Accept --- src/header/common/accept.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/header/common/accept.rs b/src/header/common/accept.rs index 97964eac9a..f58a143855 100644 --- a/src/header/common/accept.rs +++ b/src/header/common/accept.rs @@ -1,6 +1,6 @@ use mime::Mime; -use header::QualityItem; +use header::{QualityItem, qitem}; header! { /// `Accept` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.2) @@ -117,4 +117,27 @@ header! { } } +impl Accept { + /// A constructor to easily create `Accept: */*`. + pub fn star() -> Accept { + Accept(vec![qitem(mime!(Star/Star))]) + } + + /// A constructor to easily create `Accept: application/json`. + pub fn json() -> Accept { + Accept(vec![qitem(mime!(Application/Json))]) + } + + /// A constructor to easily create `Accept: text/*`. + pub fn text() -> Accept { + Accept(vec![qitem(mime!(Text/Star))]) + } + + /// A constructor to easily create `Accept: image/*`. + pub fn image() -> Accept { + Accept(vec![qitem(mime!(Image/Star))]) + } +} + + bench_header!(bench, Accept, { vec![b"text/plain; q=0.5, text/html".to_vec()] });