mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 22:49:21 +02:00
Impl BodyEncoding for Response (#740)
This commit is contained in:
@ -96,10 +96,20 @@ fn test_body_encoding_override() {
|
||||
.service(web::resource("/").route(web::to(|| {
|
||||
use actix_web::middleware::encoding::BodyEncoding;
|
||||
Response::Ok().encoding(ContentEncoding::Deflate).body(STR)
|
||||
})))
|
||||
.service(web::resource("/raw").route(web::to(|| {
|
||||
use actix_web::middleware::encoding::BodyEncoding;
|
||||
let body = actix_web::dev::Body::Bytes(STR.into());
|
||||
let mut response = Response::with_body(actix_web::http::StatusCode::OK, body);
|
||||
|
||||
response.encoding(ContentEncoding::Deflate);
|
||||
|
||||
response
|
||||
}))),
|
||||
)
|
||||
});
|
||||
|
||||
// Builder
|
||||
let mut response = srv.block_on(srv.get().no_decompress().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
@ -111,6 +121,20 @@ fn test_body_encoding_override() {
|
||||
e.write_all(bytes.as_ref()).unwrap();
|
||||
let dec = e.finish().unwrap();
|
||||
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||
|
||||
// Raw Response
|
||||
let mut response = srv.block_on(srv.request(actix_web::http::Method::GET, srv.url("/raw")).no_decompress().send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// read response
|
||||
let bytes = srv.block_on(HttpMessageBody::new(&mut response)).unwrap();
|
||||
|
||||
// decode
|
||||
let mut e = ZlibDecoder::new(Vec::new());
|
||||
e.write_all(bytes.as_ref()).unwrap();
|
||||
let dec = e.finish().unwrap();
|
||||
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
|
Reference in New Issue
Block a user