Skip to content

Commit

Permalink
feat(headers): add star, json, text, image constructors to Accept
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Dec 10, 2016
1 parent 0b02e61 commit bdc19d5
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/header/common/accept.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()] });

0 comments on commit bdc19d5

Please sign in to comment.