From 235089a1034dc93ca62f47dcab0a93f1d49c72dd Mon Sep 17 00:00:00 2001 From: Hugo Duncan Date: Sat, 7 Feb 2015 14:15:11 -0500 Subject: [PATCH] feat(headers): add AcceptCharset header Adds support for the Accept-Charset header. Encodes the charset as a string. --- src/header/common/accept_charset.rs | 27 +++++++++++++++++++++++++++ src/header/common/mod.rs | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 src/header/common/accept_charset.rs diff --git a/src/header/common/accept_charset.rs b/src/header/common/accept_charset.rs new file mode 100644 index 0000000000..75b4fb4ad4 --- /dev/null +++ b/src/header/common/accept_charset.rs @@ -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>); + +impl_list_header!(AcceptCharset, + "Accept-Charset", + Vec>); + + +#[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); +} diff --git a/src/header/common/mod.rs b/src/header/common/mod.rs index 091dc17354..3f644c3946 100644 --- a/src/header/common/mod.rs +++ b/src/header/common/mod.rs @@ -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; @@ -147,6 +148,7 @@ macro_rules! impl_header( mod access_control; mod accept; +mod accept_charset; mod accept_encoding; mod accept_language; mod allow;