Implement the basic parsing for Accept header.

This commit is contained in:
Stanislav Panferov
2014-10-06 19:56:32 +04:00
parent 46e1f4443f
commit f6ac243c85
2 changed files with 35 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
use header::Header;
use std::fmt::{mod, Show};
use std::str::from_utf8;
use mime::Mime;
/// The `Accept` header.
@@ -26,7 +27,27 @@ impl Header for Accept {
}
fn parse_header(_raw: &[Vec<u8>]) -> Option<Accept> {
unimplemented!()
let mut mimes: Vec<Mime> = vec![];
for mimes_raw in _raw.iter() {
match from_utf8(mimes_raw.as_slice()) {
Some(mimes_str) => {
for mime_str in mimes_str.split(',') {
match from_str(mime_str.trim()) {
Some(mime) => mimes.push(mime),
None => return None
}
}
},
None => return None
};
}
if !mimes.is_empty() {
Some(Accept(mimes))
} else {
// Currently is just a None, but later it can be Accept for */*
None
}
}
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {