1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use Service;
use crate::;
/// A trait for HTTP request handlers in the middleware pipeline.
///
/// `RequestHandler` is a specialized [`Service`] that processes [`HttpRequest`]s
/// and returns [`HttpResponse`]s. It serves as the foundation for building HTTP
/// middleware pipelines.
///
/// # Creating Custom Handlers
///
/// **Note**: `RequestHandler` is a sealed trait and should not be implemented directly.
/// Instead, implement [`Service<HttpRequest>`][layered::Service] with
/// `Out = Result<HttpResponse>`, and it will automatically implement `RequestHandler`.
///
/// For detailed information on creating services and middleware, see the
/// [`layered`] documentation.
///
/// # Examples
///
/// ```rust
/// # use http_extensions::{HttpRequest, HttpResponse, RequestHandler, Result};
/// # use layered::Service;
/// struct MyHandler<S>(S);
///
/// // My handler wraps another service constrained to `RequestHandler`
/// // and implements the `Service` trait with particular input and output types.
/// impl<S: RequestHandler> Service<HttpRequest> for MyHandler<S> {
/// type Out = Result<HttpResponse>;
///
/// async fn execute(&self, request: HttpRequest) -> Self::Out {
/// // do some custom processing and call the inner handler
/// self.0.execute(request).await
/// }
/// }
/// ```
pub