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

remove http-codes builders from actix-http (#2159)

This commit is contained in:
Rob Ede
2021-04-14 02:00:14 +01:00
committed by GitHub
parent 02ced426fd
commit 23e0c9b6e0
21 changed files with 539 additions and 573 deletions

View File

@ -14,8 +14,8 @@ use regex::Regex;
use actix_http::HttpMessage;
use actix_http::{
body::{Body, SizedStream},
error, http,
http::header,
error,
http::{self, header, StatusCode},
Error, HttpService, KeepAlive, Request, Response,
};
@ -28,7 +28,7 @@ async fn test_h1() {
.client_disconnect(1000)
.h1(|req: Request| {
assert!(req.peer_addr().is_some());
ok::<_, ()>(Response::Ok().finish())
ok::<_, ()>(Response::ok())
})
.tcp()
})
@ -48,7 +48,7 @@ async fn test_h1_2() {
.finish(|req: Request| {
assert!(req.peer_addr().is_some());
assert_eq!(req.version(), http::Version::HTTP_11);
ok::<_, ()>(Response::Ok().finish())
ok::<_, ()>(Response::ok())
})
.tcp()
})
@ -69,7 +69,7 @@ async fn test_expect_continue() {
err(error::ErrorPreconditionFailed("error"))
}
}))
.finish(|_| ok::<_, ()>(Response::Ok().finish()))
.finish(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -100,7 +100,7 @@ async fn test_expect_continue_h1() {
}
})
}))
.h1(fn_service(|_| ok::<_, ()>(Response::Ok().finish())))
.h1(fn_service(|_| ok::<_, ()>(Response::ok())))
.tcp()
})
.await;
@ -134,7 +134,9 @@ async fn test_chunked_payload() {
})
.fold(0usize, |acc, chunk| ready(acc + chunk.len()))
.map(|req_size| {
Ok::<_, Error>(Response::Ok().body(format!("size={}", req_size)))
Ok::<_, Error>(
Response::ok().set_body(format!("size={}", req_size)),
)
})
}))
.tcp()
@ -179,7 +181,7 @@ async fn test_slow_request() {
let srv = test_server(|| {
HttpService::build()
.client_timeout(100)
.finish(|_| ok::<_, ()>(Response::Ok().finish()))
.finish(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -195,7 +197,7 @@ async fn test_slow_request() {
async fn test_http1_malformed_request() {
let srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -211,7 +213,7 @@ async fn test_http1_malformed_request() {
async fn test_http1_keepalive() {
let srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -233,7 +235,7 @@ async fn test_http1_keepalive_timeout() {
let srv = test_server(|| {
HttpService::build()
.keep_alive(1)
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -254,7 +256,7 @@ async fn test_http1_keepalive_timeout() {
async fn test_http1_keepalive_close() {
let srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -275,7 +277,7 @@ async fn test_http1_keepalive_close() {
async fn test_http10_keepalive_default_close() {
let srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -295,7 +297,7 @@ async fn test_http10_keepalive_default_close() {
async fn test_http10_keepalive() {
let srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -323,7 +325,7 @@ async fn test_http1_keepalive_disabled() {
let srv = test_server(|| {
HttpService::build()
.keep_alive(KeepAlive::Disabled)
.h1(|_| ok::<_, ()>(Response::Ok().finish()))
.h1(|_| ok::<_, ()>(Response::ok()))
.tcp()
})
.await;
@ -394,7 +396,7 @@ async fn test_h1_headers() {
let mut srv = test_server(move || {
let data = data.clone();
HttpService::build().h1(move |_| {
let mut builder = Response::Ok();
let mut builder = Response::build(StatusCode::OK);
for idx in 0..90 {
builder.insert_header((
format!("X-TEST-{}", idx).as_str(),
@ -451,7 +453,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
async fn test_h1_body() {
let mut srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
.h1(|_| ok::<_, ()>(Response::ok().set_body(STR)))
.tcp()
})
.await;
@ -468,7 +470,7 @@ async fn test_h1_body() {
async fn test_h1_head_empty() {
let mut srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
.h1(|_| ok::<_, ()>(Response::ok().set_body(STR)))
.tcp()
})
.await;
@ -493,7 +495,7 @@ async fn test_h1_head_empty() {
async fn test_h1_head_binary() {
let mut srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
.h1(|_| ok::<_, ()>(Response::ok().set_body(STR)))
.tcp()
})
.await;
@ -518,7 +520,7 @@ async fn test_h1_head_binary() {
async fn test_h1_head_binary2() {
let srv = test_server(|| {
HttpService::build()
.h1(|_| ok::<_, ()>(Response::Ok().body(STR)))
.h1(|_| ok::<_, ()>(Response::ok().set_body(STR)))
.tcp()
})
.await;
@ -542,7 +544,7 @@ async fn test_h1_body_length() {
.h1(|_| {
let body = once(ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(
Response::Ok().body(SizedStream::new(STR.len() as u64, body)),
Response::ok().set_body(SizedStream::new(STR.len() as u64, body)),
)
})
.tcp()
@ -564,7 +566,7 @@ async fn test_h1_body_chunked_explicit() {
.h1(|_| {
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(
Response::Ok()
Response::build(StatusCode::OK)
.insert_header((header::TRANSFER_ENCODING, "chunked"))
.streaming(body),
)
@ -598,7 +600,7 @@ async fn test_h1_body_chunked_implicit() {
HttpService::build()
.h1(|_| {
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(Response::Ok().streaming(body))
ok::<_, ()>(Response::build(StatusCode::OK).streaming(body))
})
.tcp()
})
@ -628,7 +630,7 @@ async fn test_h1_response_http_error_handling() {
.h1(fn_service(|_| {
let broken_header = Bytes::from_static(b"\0\0\0");
ok::<_, ()>(
Response::Ok()
Response::build(StatusCode::OK)
.insert_header((http::header::CONTENT_TYPE, broken_header))
.body(STR),
)
@ -671,7 +673,7 @@ async fn test_h1_on_connect() {
})
.h1(|req: Request| {
assert!(req.extensions().contains::<isize>());
ok::<_, ()>(Response::Ok().finish())
ok::<_, ()>(Response::ok())
})
.tcp()
})