1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-30 00:14:58 +02:00

Various refactorings (#2281)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Igor Aleksanov
2021-06-26 18:33:43 +04:00
committed by GitHub
parent 5eba95b731
commit 262c6bc828
30 changed files with 98 additions and 121 deletions

View File

@ -1,6 +1,5 @@
use std::{future::Future, time::Instant};
use actix_http::Response;
use actix_utils::future::{ready, Ready};
use actix_web::http::StatusCode;
use actix_web::test::TestRequest;
@ -24,11 +23,11 @@ struct StringResponder(String);
impl FutureResponder for StringResponder {
type Error = Error;
type Future = Ready<Result<Response, Self::Error>>;
type Future = Ready<Result<HttpResponse, Self::Error>>;
fn future_respond_to(self, _: &HttpRequest) -> Self::Future {
// this is default builder for string response in both new and old responder trait.
ready(Ok(Response::build(StatusCode::OK)
ready(Ok(HttpResponse::build(StatusCode::OK)
.content_type("text/plain; charset=utf-8")
.body(self.0)))
}
@ -37,7 +36,7 @@ impl FutureResponder for StringResponder {
impl<T> FutureResponder for OptionResponder<T>
where
T: FutureResponder,
T::Future: Future<Output = Result<Response, Error>>,
T::Future: Future<Output = Result<HttpResponse, Error>>,
{
type Error = Error;
type Future = Either<T::Future, Ready<Result<HttpResponse, Self::Error>>>;
@ -52,7 +51,7 @@ where
impl Responder for StringResponder {
fn respond_to(self, _: &HttpRequest) -> HttpResponse {
Response::build(StatusCode::OK)
HttpResponse::build(StatusCode::OK)
.content_type("text/plain; charset=utf-8")
.body(self.0)
}
@ -62,7 +61,7 @@ impl<T: Responder> Responder for OptionResponder<T> {
fn respond_to(self, req: &HttpRequest) -> HttpResponse {
match self.0 {
Some(t) => t.respond_to(req),
None => Response::from_error(error::ErrorInternalServerError("err")),
None => HttpResponse::from_error(error::ErrorInternalServerError("err")),
}
}
}

View File

@ -51,9 +51,8 @@ where
fut.await.unwrap();
}
});
let elapsed = start.elapsed();
// check that at least first request succeeded
elapsed
start.elapsed()
})
});
}
@ -93,9 +92,8 @@ fn async_web_service(c: &mut Criterion) {
fut.await.unwrap();
}
});
let elapsed = start.elapsed();
// check that at least first request succeeded
elapsed
start.elapsed()
})
});
}