refactor(headers): Introduce header!() macro, improve documentation

The new macro handles single value headers, list headers, and list
headers with at least one item.
It creates the item for the header and contains its documentation. The
new macro allows handling
more header cases in the future, it will also be possible to include
tests inside the macro.

BREAKING CHANGE: Removed impl_header!() and impl_list_header!() macros,
use new header!() macro.
This commit is contained in:
Pyfisch
2015-04-02 12:41:04 +02:00
parent eeba13b34d
commit 262c450f90
19 changed files with 367 additions and 225 deletions

View File

@@ -2,39 +2,39 @@ use mime::Mime;
use header::QualityItem;
/// The `Accept` header.
///
/// The `Accept` header is used to tell a server which content-types the client
/// is capable of using. It can be a comma-separated list of `Mime`s, and the
/// priority can be indicated with a `q` parameter.
///
/// Example:
///
/// ```
/// # use hyper::header::Headers;
/// # use hyper::header::Accept;
/// # use hyper::header::qitem;
/// use hyper::mime::Mime;
/// use hyper::mime::TopLevel::Text;
/// use hyper::mime::SubLevel::{Html, Xml};
/// # let mut headers = Headers::new();
/// headers.set(Accept(vec![
/// qitem(Mime(Text, Html, vec![])),
/// qitem(Mime(Text, Xml, vec![])) ]));
/// ```
#[derive(Clone, PartialEq, Debug)]
pub struct Accept(pub Vec<QualityItem<Mime>>);
impl_list_header!(Accept,
"Accept",
Vec<QualityItem<Mime>>);
header! {
#[doc="`Accept` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.2)"]
#[doc=""]
#[doc="The `Accept` header field can be used by user agents to specify"]
#[doc="response media types that are acceptable. Accept header fields can"]
#[doc="be used to indicate that the request is specifically limited to a"]
#[doc="small set of desired types, as in the case of a request for an"]
#[doc="in-line image"]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Accept = #( media-range [ accept-params ] )"]
#[doc=""]
#[doc="media-range = ( \"*/*\""]
#[doc=" / ( type \"/\" \"*\" )"]
#[doc=" / ( type \"/\" subtype )"]
#[doc=" ) *( OWS \";\" OWS parameter )"]
#[doc="accept-params = weight *( accept-ext )"]
#[doc="accept-ext = OWS \";\" OWS token [ \"=\" ( token / quoted-string ) ]"]
#[doc="```"]
#[doc=""]
#[doc="# Notes"]
#[doc="* Using always Mime types to represent `media-range` differs from the ABNF."]
#[doc="* **FIXME**: `accept-ext` is not supported."]
(Accept, "Accept") => (QualityItem<Mime>)+
}
#[cfg(test)]
mod tests {
use mime::*;
use header::{Header, Quality, QualityItem, qitem};
use super::Accept;
#[test]