Skip to content

Commit

Permalink
feat(headers): add AcceptCharset header
Browse files Browse the repository at this point in the history
Adds support for the Accept-Charset header.  Encodes the charset as a
string.
  • Loading branch information
hugoduncan authored and seanmonstar committed Mar 4, 2015
1 parent 2d83a79 commit 235089a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/header/common/accept_charset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use header::{self, QualityItem};

pub type Charset = String;

/// The `Accept-Charset` header
///
/// The `Accept-Charset` header can be used by clients to indicate what
/// response charsets they accept.
#[derive(Clone, PartialEq, Debug)]
pub struct AcceptCharset(pub Vec<QualityItem<Charset>>);

impl_list_header!(AcceptCharset,
"Accept-Charset",
Vec<QualityItem<Charset>>);


#[test]
fn test_parse_header() {
let a: AcceptCharset = header::Header::parse_header(
[b"iso-8859-5, unicode-1-1;q=0.8".to_vec()].as_slice()).unwrap();
let b = AcceptCharset(vec![
QualityItem{item: "iso-8859-5".to_string(), quality: 1.0},
QualityItem{item: "unicode-1-1".to_string(), quality: 0.8},
]);
assert_eq!(format!("{}", a), format!("{}", b));
assert_eq!(a, b);
}
2 changes: 2 additions & 0 deletions src/header/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

pub use self::access_control::*;
pub use self::accept::Accept;
pub use self::accept_charset::AcceptCharset;
pub use self::accept_encoding::AcceptEncoding;
pub use self::accept_language::AcceptLanguage;
pub use self::allow::Allow;
Expand Down Expand Up @@ -147,6 +148,7 @@ macro_rules! impl_header(

mod access_control;
mod accept;
mod accept_charset;
mod accept_encoding;
mod accept_language;
mod allow;
Expand Down

0 comments on commit 235089a

Please sign in to comment.