refactor(headers): errors for parse_header

Header::parse_header() returns now a hyper Result instead of an option
this will enable more precise Error messages in the future, currently
most failures are reported as ::Error::Header.

BREAKING CHANGE: parse_header returns Result instead of Option, related
code did also change
This commit is contained in:
Pyfisch
2015-06-06 22:04:01 +02:00
parent 763746153e
commit 195a89fa91
19 changed files with 140 additions and 132 deletions

View File

@@ -36,16 +36,16 @@ impl Header for IfRange {
fn header_name() -> &'static str {
"If-Range"
}
fn parse_header(raw: &[Vec<u8>]) -> Option<IfRange> {
let etag: Option<EntityTag> = header::parsing::from_one_raw_str(raw);
if etag != None {
return Some(IfRange::EntityTag(etag.unwrap()));
fn parse_header(raw: &[Vec<u8>]) -> ::Result<IfRange> {
let etag: ::Result<EntityTag> = header::parsing::from_one_raw_str(raw);
if etag.is_ok() {
return Ok(IfRange::EntityTag(etag.unwrap()));
}
let date: Option<HttpDate> = header::parsing::from_one_raw_str(raw);
if date != None {
return Some(IfRange::Date(date.unwrap()));
let date: ::Result<HttpDate> = header::parsing::from_one_raw_str(raw);
if date.is_ok() {
return Ok(IfRange::Date(date.unwrap()));
}
None
Err(::Error::Header)
}
}