Split common headers into a submodule and into their own files

This is a more extensible place to put them and doesn't clutter up
header/mod.rs as much as the old scheme did.

Fixes #8
This commit is contained in:
Jonathan Reem
2014-09-08 16:12:47 -07:00
parent fd6b014e7e
commit f2c09c5743
17 changed files with 727 additions and 637 deletions

View File

@@ -0,0 +1,44 @@
use header::Header;
use std::fmt::{mod, Show};
use mime::Mime;
/// 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::common::Accept;
/// use hyper::mime::{Mime, Text, Html, Xml};
/// # let mut headers = Headers::new();
/// headers.set(Accept(vec![ Mime(Text, Html, vec![]), Mime(Text, Xml, vec![]) ]));
/// ```
#[deriving(Clone, PartialEq, Show)]
pub struct Accept(pub Vec<Mime>);
impl Header for Accept {
fn header_name(_: Option<Accept>) -> &'static str {
"accept"
}
fn parse_header(_raw: &[Vec<u8>]) -> Option<Accept> {
unimplemented!()
}
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Accept(ref value) = *self;
let last = value.len() - 1;
for (i, mime) in value.iter().enumerate() {
try!(mime.fmt(fmt));
if i < last {
try!(", ".fmt(fmt));
}
}
Ok(())
}
}