feat(langtags): use true language tags in headers

Make hyper dependant on rust-language-tags providing complete parsing
and formatting of language tags. Remove builtin solution for simple
tags.

BREAKING CHANGE: AcceptLanguage and ContentLanguage use LanguageTag now,
Language removed from Hyper.
This commit is contained in:
Pyfisch
2015-06-23 18:27:19 +02:00
parent c3935d657e
commit 99ff7e6257
7 changed files with 54 additions and 112 deletions

View File

@@ -1,45 +0,0 @@
use std::str::FromStr;
use std::fmt;
/// A language tag.
/// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.10
///
/// Note: This is no complete language tag implementation, it should be replaced with
/// github.com/pyfisch/rust-language-tag once it is ready.
#[derive(Clone, PartialEq, Debug)]
pub struct Language {
/// The language tag
pub primary: String,
/// A language subtag or country code
pub sub: Option<String>
}
impl FromStr for Language {
type Err = ::Error;
fn from_str(s: &str) -> ::Result<Language> {
let mut i = s.split("-");
let p = i.next();
let s = i.next();
match (p, s) {
(Some(p), Some(s)) => Ok(Language {
primary: p.to_owned(),
sub: Some(s.to_owned())
}),
(Some(p), _) => Ok(Language {
primary: p.to_owned(),
sub: None
}),
_ => Err(::Error::Header)
}
}
}
impl fmt::Display for Language {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(f.write_str(&self.primary[..]));
match self.sub {
Some(ref s) => write!(f, "-{}", s),
None => Ok(())
}
}
}

View File

@@ -2,12 +2,10 @@ pub use self::charset::Charset;
pub use self::encoding::Encoding;
pub use self::entity::EntityTag;
pub use self::httpdate::HttpDate;
pub use self::language::Language;
pub use self::quality_item::{Quality, QualityItem, qitem, q};
mod charset;
mod encoding;
mod entity;
mod httpdate;
mod language;
mod quality_item;