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

remove impl Future for HttpResponse (#2601)

This commit is contained in:
Rob Ede
2022-01-24 11:56:01 +00:00
committed by GitHub
parent 50894e392e
commit d7c5c966d2
13 changed files with 182 additions and 139 deletions

View File

@ -30,7 +30,9 @@ const STR: &str = const_str::repeat!(S, 100);
#[actix_rt::test]
async fn test_simple() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))))
App::new().service(
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
)
});
let request = srv.get("/").insert_header(("x-test", "111")).send();
@ -93,7 +95,7 @@ async fn test_timeout() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| async {
actix_rt::time::sleep(Duration::from_millis(200)).await;
Ok::<_, Error>(HttpResponse::Ok().body(STR))
HttpResponse::Ok().body(STR)
})))
});
@ -118,7 +120,7 @@ async fn test_timeout_override() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| async {
actix_rt::time::sleep(Duration::from_millis(200)).await;
Ok::<_, Error>(HttpResponse::Ok().body(STR))
HttpResponse::Ok().body(STR)
})))
});
@ -295,10 +297,9 @@ async fn test_connection_server_close() {
})
.and_then(
HttpService::new(map_config(
App::new().service(
web::resource("/")
.route(web::to(|| HttpResponse::Ok().force_close().finish())),
),
App::new().service(web::resource("/").route(web::to(|| async {
HttpResponse::Ok().force_close().finish()
}))),
|_| AppConfig::default(),
))
.tcp(),
@ -336,7 +337,8 @@ async fn test_connection_wait_queue() {
.and_then(
HttpService::new(map_config(
App::new().service(
web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))),
web::resource("/")
.route(web::to(|| async { HttpResponse::Ok().body(STR) })),
),
|_| AppConfig::default(),
))
@ -383,10 +385,9 @@ async fn test_connection_wait_queue_force_close() {
})
.and_then(
HttpService::new(map_config(
App::new().service(
web::resource("/")
.route(web::to(|| HttpResponse::Ok().force_close().body(STR))),
),
App::new().service(web::resource("/").route(web::to(|| async {
HttpResponse::Ok().force_close().body(STR)
}))),
|_| AppConfig::default(),
))
.tcp(),
@ -445,7 +446,9 @@ async fn test_no_decompress() {
let srv = actix_test::start(|| {
App::new()
.wrap(actix_web::middleware::Compress::default())
.service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))))
.service(
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
)
});
let mut res = awc::Client::new()
@ -479,7 +482,7 @@ async fn test_no_decompress() {
#[actix_rt::test]
async fn test_client_gzip_encoding() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| {
App::new().service(web::resource("/").route(web::to(|| async {
HttpResponse::Ok()
.insert_header(header::ContentEncoding::Gzip)
.body(utils::gzip::encode(STR))
@ -499,7 +502,7 @@ async fn test_client_gzip_encoding() {
#[actix_rt::test]
async fn test_client_gzip_encoding_large() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| {
App::new().service(web::resource("/").route(web::to(|| async {
HttpResponse::Ok()
.insert_header(header::ContentEncoding::Gzip)
.body(utils::gzip::encode(STR.repeat(10)))
@ -525,7 +528,7 @@ async fn test_client_gzip_encoding_large_random() {
.collect::<String>();
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
HttpResponse::Ok()
.insert_header(header::ContentEncoding::Gzip)
.body(utils::gzip::encode(data))
@ -545,7 +548,7 @@ async fn test_client_gzip_encoding_large_random() {
#[actix_rt::test]
async fn test_client_brotli_encoding() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
HttpResponse::Ok()
.insert_header(("content-encoding", "br"))
.body(utils::brotli::encode(data))
@ -571,10 +574,10 @@ async fn test_client_brotli_encoding_large_random() {
.collect::<String>();
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
HttpResponse::Ok()
.insert_header(header::ContentEncoding::Brotli)
.body(utils::brotli::encode(&data))
.body(utils::brotli::encode(data))
})))
});
@ -590,7 +593,9 @@ async fn test_client_brotli_encoding_large_random() {
#[actix_rt::test]
async fn test_client_deflate_encoding() {
let srv = actix_test::start(|| {
App::new().default_service(web::to(|body: Bytes| HttpResponse::Ok().body(body)))
App::new().default_service(web::to(|body: Bytes| async {
HttpResponse::Ok().body(body)
}))
});
let req = srv
@ -614,7 +619,9 @@ async fn test_client_deflate_encoding_large_random() {
.collect::<String>();
let srv = actix_test::start(|| {
App::new().default_service(web::to(|body: Bytes| HttpResponse::Ok().body(body)))
App::new().default_service(web::to(|body: Bytes| async {
HttpResponse::Ok().body(body)
}))
});
let req = srv
@ -632,7 +639,7 @@ async fn test_client_deflate_encoding_large_random() {
#[actix_rt::test]
async fn test_client_streaming_explicit() {
let srv = actix_test::start(|| {
App::new().default_service(web::to(|body: web::Payload| {
App::new().default_service(web::to(|body: web::Payload| async {
HttpResponse::Ok().streaming(body)
}))
});
@ -654,7 +661,7 @@ async fn test_client_streaming_explicit() {
#[actix_rt::test]
async fn test_body_streaming_implicit() {
let srv = actix_test::start(|| {
App::new().default_service(web::to(|| {
App::new().default_service(web::to(|| async {
let body =
stream::once(async { Ok::<_, Infallible>(Bytes::from_static(STR.as_bytes())) });
HttpResponse::Ok().streaming(body)