1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-26 15:07:42 +02:00

refined error model (#2253)

This commit is contained in:
Rob Ede
2021-06-17 17:57:58 +01:00
committed by GitHub
parent bb0331ae28
commit 532f7b9923
69 changed files with 1498 additions and 901 deletions

View File

@ -1,5 +1,7 @@
use std::convert::Infallible;
use actix_http::{
http, http::StatusCode, HttpMessage, HttpService, Request, Response, ResponseError,
body::AnyBody, http, http::StatusCode, HttpMessage, HttpService, Request, Response,
};
use actix_http_test::test_server;
use actix_service::ServiceFactoryExt;
@ -34,7 +36,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
async fn test_h1_v2() {
let srv = test_server(move || {
HttpService::build()
.finish(|_| future::ok::<_, ()>(Response::ok().set_body(STR)))
.finish(|_| future::ok::<_, Infallible>(Response::ok().set_body(STR)))
.tcp()
})
.await;
@ -62,7 +64,7 @@ async fn test_h1_v2() {
async fn test_connection_close() {
let srv = test_server(move || {
HttpService::build()
.finish(|_| future::ok::<_, ()>(Response::ok().set_body(STR)))
.finish(|_| future::ok::<_, Infallible>(Response::ok().set_body(STR)))
.tcp()
.map(|_| ())
})
@ -76,11 +78,11 @@ async fn test_connection_close() {
async fn test_with_query_parameter() {
let srv = test_server(move || {
HttpService::build()
.finish(|req: Request| {
.finish(|req: Request| async move {
if req.uri().query().unwrap().contains("qp=") {
future::ok::<_, ()>(Response::ok())
Ok::<_, Infallible>(Response::ok())
} else {
future::ok::<_, ()>(Response::bad_request())
Ok(Response::bad_request())
}
})
.tcp()
@ -97,9 +99,9 @@ async fn test_with_query_parameter() {
#[display(fmt = "expect failed")]
struct ExpectFailed;
impl ResponseError for ExpectFailed {
fn status_code(&self) -> StatusCode {
StatusCode::EXPECTATION_FAILED
impl From<ExpectFailed> for Response<AnyBody> {
fn from(_: ExpectFailed) -> Self {
Response::new(StatusCode::EXPECTATION_FAILED)
}
}
@ -123,7 +125,7 @@ async fn test_h1_expect() {
let str = std::str::from_utf8(&buf).unwrap();
assert_eq!(str, "expect body");
Ok::<_, ()>(Response::ok())
Ok::<_, Infallible>(Response::ok())
})
.tcp()
})