stedi_sdk_client_guides/
middleware.rs1macro_rules! stack_type {
4 ($first: ty, $($rest:ty),+) => {
5 tower::layer::util::Stack<$first, stack_type!($($rest),+)>
6 };
7 ($only: ty) => {
8 tower::layer::util::Stack<$only, tower::layer::util::Identity>
9 }
10 }
11type DefaultMiddlewareStack = stack_type!(
13 aws_smithy_http_tower::map_request::MapRequestLayer<
14 aws_http::recursion_detection::RecursionDetectionStage,
15 >,
16 aws_smithy_http_tower::map_request::MapRequestLayer<aws_http::user_agent::UserAgentStage>,
17 aws_smithy_http_tower::map_request::MapRequestLayer<aws_endpoint::AwsAuthStage>,
18 aws_smithy_http_tower::map_request::MapRequestLayer<
19 aws_smithy_http::endpoint::middleware::SmithyEndpointStage,
20 >
21);
22#[derive(std::fmt::Debug, Default, Clone)]
24#[non_exhaustive]
25pub struct DefaultMiddleware;
26
27impl DefaultMiddleware {
28 pub fn new() -> Self {
32 DefaultMiddleware::default()
33 }
34}
35fn base() -> tower::ServiceBuilder<DefaultMiddlewareStack> {
37 let endpoint_stage = aws_smithy_http_tower::map_request::MapRequestLayer::for_mapper(
38 aws_smithy_http::endpoint::middleware::SmithyEndpointStage::new(),
39 );
40 let auth_stage =
41 aws_smithy_http_tower::map_request::MapRequestLayer::for_mapper(aws_endpoint::AwsAuthStage);
42 let user_agent = aws_smithy_http_tower::map_request::MapRequestLayer::for_mapper(
43 aws_http::user_agent::UserAgentStage::new(),
44 );
45 let recursion_detection = aws_smithy_http_tower::map_request::MapRequestLayer::for_mapper(
46 aws_http::recursion_detection::RecursionDetectionStage::new(),
47 );
48 tower::ServiceBuilder::new()
49 .layer(endpoint_stage)
50 .layer(auth_stage)
51 .layer(user_agent)
52 .layer(recursion_detection)
53}
54impl<S> tower::Layer<S> for DefaultMiddleware {
55 type Service = <DefaultMiddlewareStack as tower::Layer<S>>::Service;
56
57 fn layer(&self, inner: S) -> Self::Service {
58 base().service(inner)
59 }
60}