From 6281a0bea6054d2b9552f28fa85daf4b7a03bd91 Mon Sep 17 00:00:00 2001 From: Malloc Voidstar <1284317+AlyoshaVasilieva@users.noreply.github.com> Date: Tue, 5 Oct 2021 08:43:08 -0700 Subject: [PATCH] Add tests for automatic decompression --- src/test/body_read.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/test/body_read.rs b/src/test/body_read.rs index c527981..c15e7c5 100644 --- a/src/test/body_read.rs +++ b/src/test/body_read.rs @@ -82,3 +82,45 @@ fn no_reader_on_head() { reader.read_to_string(&mut text).unwrap(); 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()); +}