1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use header::{Header, HeaderFormat};
use std::fmt;
use header::shared::util::from_one_raw_str;
use mime::Mime;
#[derive(Clone, PartialEq, Show)]
pub struct ContentType(pub Mime);
deref!(ContentType => Mime);
impl Header for ContentType {
fn header_name(_: Option<ContentType>) -> &'static str {
"Content-Type"
}
fn parse_header(raw: &[Vec<u8>]) -> Option<ContentType> {
from_one_raw_str(raw).map(|mime| ContentType(mime))
}
}
impl HeaderFormat for ContentType {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&self.0, fmt)
}
}
bench_header!(bench, ContentType, { vec![b"application/json; charset=utf-8".to_vec()] });