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

@@ -1,11 +1,20 @@
/// The `Server` header field.
///
/// They can contain any value, so it just wraps a `String`.
#[derive(Clone, PartialEq, Debug)]
pub struct Server(pub String);
impl_header!(Server,
"Server",
String);
header! {
#[doc="`Server` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.2)"]
#[doc=""]
#[doc="The `Server` header field contains information about the software"]
#[doc="used by the origin server to handle the request, which is often used"]
#[doc="by clients to help identify the scope of reported interoperability"]
#[doc="problems, to work around or tailor requests to avoid particular"]
#[doc="server limitations, and for analytics regarding server or operating"]
#[doc="system use. An origin server MAY generate a Server field in its"]
#[doc="responses."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Server = product *( RWS ( product / comment ) )"]
#[doc="```"]
// TODO: Maybe parse as defined in the spec?
(Server, "Server") => [String]
}
bench_header!(bench, Server, { vec![b"Some String".to_vec()] });