1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 22:49:21 +02:00

App::enable_encoding() allows to enable compression and decompression

This commit is contained in:
Nikolay Kim
2019-03-28 12:32:59 -07:00
parent 5795850bbb
commit 605ce05127
2 changed files with 94 additions and 33 deletions

View File

@ -335,6 +335,34 @@ fn test_body_brotli() {
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
}
#[test]
fn test_encoding() {
let mut srv = TestServer::new(move || {
HttpService::new(
App::new().enable_encoding().service(
web::resource("/")
.route(web::to(move |body: Bytes| Response::Ok().body(body))),
),
)
});
// client request
let mut e = GzEncoder::new(Vec::new(), Compression::default());
e.write_all(STR.as_ref()).unwrap();
let enc = e.finish().unwrap();
let request = srv
.post()
.header(CONTENT_ENCODING, "gzip")
.send_body(enc.clone());
let mut response = srv.block_on(request).unwrap();
assert!(response.status().is_success());
// read response
let bytes = srv.block_on(HttpMessageBody::new(&mut response)).unwrap();
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
}
#[test]
fn test_gzip_encoding() {
let mut srv = TestServer::new(move || {