Skip to content

Commit 291009e

Browse files
committed
Accept-Encoding wildcard support
1 parent e712464 commit 291009e

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/content/accept_encoding.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ impl AcceptEncoding {
9191
};
9292
}
9393

94+
if self.wildcard {
95+
match output.len() {
96+
0 => write!(output, "*").unwrap(),
97+
_ => write!(output, ", *").unwrap(),
98+
}
99+
}
100+
94101
// SAFETY: the internal string is validated to be ASCII.
95102
unsafe { HeaderValue::from_bytes_unchecked(output.into()) }
96103
}
@@ -232,8 +239,35 @@ mod test {
232239
accept.apply(&mut headers);
233240

234241
let accept = AcceptEncoding::from_headers(headers)?.unwrap();
235-
let mut accept = accept.iter();
236-
assert_eq!(accept.next().unwrap(), Encoding::Gzip);
242+
assert_eq!(accept.iter().next().unwrap(), Encoding::Gzip);
243+
Ok(())
244+
}
245+
246+
#[test]
247+
fn wildcard() -> crate::Result<()> {
248+
let mut accept = AcceptEncoding::new();
249+
accept.set_wildcard(true);
250+
251+
let mut headers = Response::new(200);
252+
accept.apply(&mut headers);
253+
254+
let accept = AcceptEncoding::from_headers(headers)?.unwrap();
255+
assert!(accept.wildcard());
256+
Ok(())
257+
}
258+
259+
#[test]
260+
fn wildcard_and_header() -> crate::Result<()> {
261+
let mut accept = AcceptEncoding::new();
262+
accept.push(Encoding::Gzip);
263+
accept.set_wildcard(true);
264+
265+
let mut headers = Response::new(200);
266+
accept.apply(&mut headers);
267+
268+
let accept = AcceptEncoding::from_headers(headers)?.unwrap();
269+
assert!(accept.wildcard());
270+
assert_eq!(accept.iter().next().unwrap(), Encoding::Gzip);
237271
Ok(())
238272
}
239273
}

0 commit comments

Comments
 (0)