mirror of
https://github.com/actix/actix-web.git
synced 2024-06-10 09:19:35 +00:00
32 lines
1,007 B
Rust
32 lines
1,007 B
Rust
|
use actix_utils::future::ok;
|
||
|
|
||
|
use crate::{
|
||
|
body::BoxBody,
|
||
|
dev::{fn_service, Service, ServiceRequest, ServiceResponse},
|
||
|
http::StatusCode,
|
||
|
Error, HttpResponseBuilder,
|
||
|
};
|
||
|
|
||
|
/// Creates service that always responds with `200 OK` and no body.
|
||
|
pub fn ok_service(
|
||
|
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
||
|
simple_service(StatusCode::OK)
|
||
|
}
|
||
|
|
||
|
/// Creates service that always responds with given status code and no body.
|
||
|
pub fn simple_service(
|
||
|
status_code: StatusCode,
|
||
|
) -> impl Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> {
|
||
|
fn_service(move |req: ServiceRequest| {
|
||
|
ok(req.into_response(HttpResponseBuilder::new(status_code).finish()))
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[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)
|
||
|
}
|