This commit is contained in:
Rob Ede 2021-12-22 07:41:49 +00:00
parent e48847efac
commit 3f6d853d2f
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 23 additions and 1 deletions

View File

@ -82,7 +82,7 @@ where
T: ServiceFactory<
ServiceRequest,
Config = (),
Response = ServiceResponse,
Response = ServiceResponse<B>,
Error = Error,
InitError = (),
>,
@ -813,4 +813,26 @@ mod tests {
let resp = call_service(&srv, req).await;
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
#[actix_rt::test]
async fn test_middleware_body_type() {
let srv = init_service(
App::new().service(
web::resource("/test")
.wrap_fn(|req, srv| {
let fut = srv.call(req);
async { Ok(fut.await?.map_into_right_body::<()>()) }
})
.route(web::get().to(|| async { "hello" })),
),
)
.await;
// test if `try_into_bytes()` is preserved across scope layer
use actix_http::body::MessageBody as _;
let req = TestRequest::with_uri("/test").to_request();
let resp = call_service(&srv, req).await;
let body = resp.into_body();
assert_eq!(body.try_into_bytes().unwrap(), b"hello".as_ref());
}
}