Add tests for automatic decompression
This commit is contained in:
committed by
Martin Algesten
parent
9a070fb1ad
commit
6281a0bea6
@@ -82,3 +82,45 @@ fn no_reader_on_head() {
|
|||||||
reader.read_to_string(&mut text).unwrap();
|
reader.read_to_string(&mut text).unwrap();
|
||||||
assert_eq!(text, "");
|
assert_eq!(text, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gzip")]
|
||||||
|
#[test]
|
||||||
|
fn gzip_text() {
|
||||||
|
test::set_handler("/gzip_text", |_unit| {
|
||||||
|
test::make_response(
|
||||||
|
200,
|
||||||
|
"OK",
|
||||||
|
vec!["content-length: 35", "content-encoding: gzip"],
|
||||||
|
vec![
|
||||||
|
0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0xCB, 0x48, 0xCD, 0xC9,
|
||||||
|
0xC9, 0x57, 0x28, 0xCF, 0x2F, 0xCA, 0x49, 0x51, 0xC8, 0x18, 0xBC, 0x6C, 0x00, 0xA5,
|
||||||
|
0x5C, 0x7C, 0xEF, 0xA7, 0x00, 0x00, 0x00,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
});
|
||||||
|
// echo -n INPUT | gzip -9 -f | hexdump -ve '1/1 "0x%.2X,"'
|
||||||
|
// INPUT is `hello world ` repeated 14 times, no trailing space
|
||||||
|
let resp = get("test://host/gzip_text").call().unwrap();
|
||||||
|
let text = resp.into_string().unwrap();
|
||||||
|
assert_eq!(text, "hello world ".repeat(14).trim_end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "brotli")]
|
||||||
|
#[test]
|
||||||
|
fn brotli_text() {
|
||||||
|
test::set_handler("/brotli_text", |_unit| {
|
||||||
|
test::make_response(
|
||||||
|
200,
|
||||||
|
"OK",
|
||||||
|
vec!["content-length: 24", "content-encoding: br"],
|
||||||
|
vec![
|
||||||
|
0x1F, 0xA6, 0x00, 0xF8, 0x8D, 0x94, 0x6E, 0xDE, 0x44, 0x55, 0x86, 0x96, 0x20, 0x6C,
|
||||||
|
0x6F, 0x35, 0x8B, 0x62, 0xB5, 0x40, 0x06, 0x54, 0xBB, 0x02,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
});
|
||||||
|
// echo -n INPUT | brotli -Z -f | hexdump -ve '1/1 "0x%.2X,"'
|
||||||
|
let resp = get("test://host/brotli_text").call().unwrap();
|
||||||
|
let text = resp.into_string().unwrap();
|
||||||
|
assert_eq!(text, "hello world ".repeat(14).trim_end());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user