Skip to content

Commit 235089a

Browse files
hugoduncanseanmonstar
authored andcommittedMar 4, 2015
feat(headers): add AcceptCharset header
Adds support for the Accept-Charset header. Encodes the charset as a string.
1 parent 2d83a79 commit 235089a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎src/header/common/accept_charset.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use header::{self, QualityItem};
2+
3+
pub type Charset = String;
4+
5+
/// The `Accept-Charset` header
6+
///
7+
/// The `Accept-Charset` header can be used by clients to indicate what
8+
/// response charsets they accept.
9+
#[derive(Clone, PartialEq, Debug)]
10+
pub struct AcceptCharset(pub Vec<QualityItem<Charset>>);
11+
12+
impl_list_header!(AcceptCharset,
13+
"Accept-Charset",
14+
Vec<QualityItem<Charset>>);
15+
16+
17+
#[test]
18+
fn test_parse_header() {
19+
let a: AcceptCharset = header::Header::parse_header(
20+
[b"iso-8859-5, unicode-1-1;q=0.8".to_vec()].as_slice()).unwrap();
21+
let b = AcceptCharset(vec![
22+
QualityItem{item: "iso-8859-5".to_string(), quality: 1.0},
23+
QualityItem{item: "unicode-1-1".to_string(), quality: 0.8},
24+
]);
25+
assert_eq!(format!("{}", a), format!("{}", b));
26+
assert_eq!(a, b);
27+
}

‎src/header/common/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
pub use self::access_control::*;
1010
pub use self::accept::Accept;
11+
pub use self::accept_charset::AcceptCharset;
1112
pub use self::accept_encoding::AcceptEncoding;
1213
pub use self::accept_language::AcceptLanguage;
1314
pub use self::allow::Allow;
@@ -147,6 +148,7 @@ macro_rules! impl_header(
147148

148149
mod access_control;
149150
mod accept;
151+
mod accept_charset;
150152
mod accept_encoding;
151153
mod accept_language;
152154
mod allow;

0 commit comments

Comments
 (0)