mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 22:49:21 +02:00
more tests
This commit is contained in:
@ -17,7 +17,7 @@ use futures::stream::once;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
|
||||
use actix_web::middleware::{BodyEncoding, Compress};
|
||||
use actix_web::{http, test, web, App, HttpResponse, HttpServer};
|
||||
use actix_web::{dev, http, test, web, App, HttpResponse, HttpServer};
|
||||
|
||||
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
||||
Hello World Hello World Hello World Hello World Hello World \
|
||||
@ -89,6 +89,39 @@ fn test_body_gzip() {
|
||||
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
#[test]
|
||||
fn test_body_gzip2() {
|
||||
let mut srv = TestServer::new(|| {
|
||||
h1::H1Service::new(
|
||||
App::new()
|
||||
.wrap(Compress::new(ContentEncoding::Gzip))
|
||||
.service(web::resource("/").route(web::to(|| {
|
||||
Response::Ok().body(STR).into_body::<dev::Body>()
|
||||
}))),
|
||||
)
|
||||
});
|
||||
|
||||
let mut response = srv
|
||||
.block_on(
|
||||
srv.get("/")
|
||||
.no_decompress()
|
||||
.header(ACCEPT_ENCODING, "gzip")
|
||||
.send(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(response.body()).unwrap();
|
||||
|
||||
// decode
|
||||
let mut e = GzDecoder::new(&bytes[..]);
|
||||
let mut dec = Vec::new();
|
||||
e.read_to_end(&mut dec).unwrap();
|
||||
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
#[test]
|
||||
fn test_body_encoding_override() {
|
||||
|
Reference in New Issue
Block a user