refactor(headers): Use macros for headers where possible

This commit is contained in:
Pyfisch
2015-02-16 19:26:40 +01:00
parent f554c09e12
commit de1be67262
11 changed files with 70 additions and 202 deletions

View File

@@ -1,7 +1,3 @@
use header::{Header, HeaderFormat};
use std::fmt;
use header::parsing::from_one_raw_str;
/// The `Referer` header.
///
/// The Referer header is used by user agents to inform server about
@@ -13,22 +9,8 @@ use header::parsing::from_one_raw_str;
#[derive(Clone, PartialEq, Debug)]
pub struct Referer(pub String);
deref!(Referer => String);
impl Header for Referer {
fn header_name() -> &'static str {
"Referer"
}
fn parse_header(raw: &[Vec<u8>]) -> Option<Referer> {
from_one_raw_str(raw).map(|s| Referer(s))
}
}
impl HeaderFormat for Referer {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0, fmt)
}
}
impl_header!(Referer,
"Referer",
String);
bench_header!(bench, Referer, { vec![b"http://foo.com/hello:3000".to_vec()] });