mirror of https://github.com/fafhrd91/actix-web
rename default_service to simple_service
This commit is contained in:
parent
1d871fa187
commit
84d7320f42
|
@ -42,8 +42,8 @@ use actix_http::{header::HeaderMap, ws, HttpService, Method, Request, Response};
|
||||||
pub use actix_http_test::unused_addr;
|
pub use actix_http_test::unused_addr;
|
||||||
use actix_service::{map_config, IntoServiceFactory, ServiceFactory, ServiceFactoryExt as _};
|
use actix_service::{map_config, IntoServiceFactory, ServiceFactory, ServiceFactoryExt as _};
|
||||||
pub use actix_web::test::{
|
pub use actix_web::test::{
|
||||||
call_service, default_service, init_service, ok_service, read_body, read_body_json,
|
call_service, init_service, ok_service, read_body, read_body_json, read_response,
|
||||||
read_response, read_response_json, TestRequest,
|
read_response_json, simple_service, TestRequest,
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
body::MessageBody,
|
body::MessageBody,
|
||||||
|
|
|
@ -194,7 +194,7 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::ServiceRequest,
|
dev::ServiceRequest,
|
||||||
http::header::CONTENT_TYPE,
|
http::header::CONTENT_TYPE,
|
||||||
test::{ok_service, TestRequest},
|
test::{self, TestRequest},
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ mod tests {
|
||||||
let mw = DefaultHeaders::new()
|
let mw = DefaultHeaders::new()
|
||||||
.add(("X-TEST", "0001"))
|
.add(("X-TEST", "0001"))
|
||||||
.add(("X-TEST-TWO", HeaderValue::from_static("123")))
|
.add(("X-TEST-TWO", HeaderValue::from_static("123")))
|
||||||
.new_transform(ok_service())
|
.new_transform(test::ok_service())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -234,10 +234,9 @@ mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn adding_content_type() {
|
async fn adding_content_type() {
|
||||||
let srv = |req: ServiceRequest| ok(req.into_response(HttpResponse::Ok().finish()));
|
|
||||||
let mw = DefaultHeaders::new()
|
let mw = DefaultHeaders::new()
|
||||||
.add_content_type()
|
.add_content_type()
|
||||||
.new_transform(srv.into_service())
|
.new_transform(test::ok_service())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ mod tests {
|
||||||
Ok(ErrorHandlerResponse::Response(res.map_into_left_body()))
|
Ok(ErrorHandlerResponse::Response(res.map_into_left_body()))
|
||||||
}
|
}
|
||||||
|
|
||||||
let srv = test::default_service(StatusCode::INTERNAL_SERVER_ERROR);
|
let srv = test::simple_service(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
let mw = ErrorHandlers::new()
|
let mw = ErrorHandlers::new()
|
||||||
.handler(StatusCode::INTERNAL_SERVER_ERROR, error_handler)
|
.handler(StatusCode::INTERNAL_SERVER_ERROR, error_handler)
|
||||||
|
@ -236,7 +236,7 @@ mod tests {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
let srv = test::default_service(StatusCode::INTERNAL_SERVER_ERROR);
|
let srv = test::simple_service(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
let mw = ErrorHandlers::new()
|
let mw = ErrorHandlers::new()
|
||||||
.handler(StatusCode::INTERNAL_SERVER_ERROR, error_handler)
|
.handler(StatusCode::INTERNAL_SERVER_ERROR, error_handler)
|
||||||
|
@ -264,7 +264,7 @@ mod tests {
|
||||||
Ok(ErrorHandlerResponse::Response(res))
|
Ok(ErrorHandlerResponse::Response(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
let srv = test::default_service(StatusCode::INTERNAL_SERVER_ERROR);
|
let srv = test::simple_service(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
let mw = ErrorHandlers::new()
|
let mw = ErrorHandlers::new()
|
||||||
.handler(StatusCode::INTERNAL_SERVER_ERROR, error_handler)
|
.handler(StatusCode::INTERNAL_SERVER_ERROR, error_handler)
|
||||||
|
|
16
src/test.rs
16
src/test.rs
|
@ -27,14 +27,14 @@ use crate::{
|
||||||
Error, HttpRequest, HttpResponse, HttpResponseBuilder,
|
Error, HttpRequest, HttpResponse, HttpResponseBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Create service that always responds with `HttpResponse::Ok()` and no body.
|
/// Creates service that always responds with `200 OK` and no body.
|
||||||
pub fn ok_service(
|
pub fn ok_service(
|
||||||
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
||||||
default_service(StatusCode::OK)
|
simple_service(StatusCode::OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create service that always responds with given status code and no body.
|
/// Creates service that always responds with given status code and no body.
|
||||||
pub fn default_service(
|
pub fn simple_service(
|
||||||
status_code: StatusCode,
|
status_code: StatusCode,
|
||||||
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
||||||
(move |req: ServiceRequest| {
|
(move |req: ServiceRequest| {
|
||||||
|
@ -43,6 +43,14 @@ pub fn default_service(
|
||||||
.into_service()
|
.into_service()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[deprecated(since = "4.0.0", note = "Renamed to `simple_service`.")]
|
||||||
|
pub fn default_service(
|
||||||
|
status_code: StatusCode,
|
||||||
|
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
||||||
|
simple_service(status_code)
|
||||||
|
}
|
||||||
|
|
||||||
/// Initialize service from application builder instance.
|
/// Initialize service from application builder instance.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
|
Loading…
Reference in New Issue