1pub mod echo;
9pub mod fs;
10pub mod geo;
11pub mod http_security;
12pub mod ip;
13pub mod wire_names;
14
15#[cfg(feature = "quic")]
16use {
17 crate::{Service, quic},
18 std::convert::Infallible,
19};
20
21use crate::{
22 cli::ForwardKind,
23 combinators::Either7,
24 http::{
25 headers::forwarded::{
26 CFConnectingIp, ClientIp, TrueClientIp, XClientIp, XForwardedFor, XRealIp,
27 },
28 layer::forwarded::GetForwardedHeaderLayer,
29 },
30};
31
32#[cfg(feature = "quic")]
35trait MaybeHttp3Service: Service<quic::Connection, Output = (), Error = Infallible> {}
36#[cfg(feature = "quic")]
37impl<S: Service<quic::Connection, Output = (), Error = Infallible>> MaybeHttp3Service for S {}
38#[cfg(not(feature = "quic"))]
39trait MaybeHttp3Service {}
40#[cfg(not(feature = "quic"))]
41impl<T> MaybeHttp3Service for T {}
42
43type HttpForwardedLayer = Option<
48 Either7<
49 GetForwardedHeaderLayer,
50 GetForwardedHeaderLayer<XForwardedFor>,
51 GetForwardedHeaderLayer<XClientIp>,
52 GetForwardedHeaderLayer<ClientIp>,
53 GetForwardedHeaderLayer<XRealIp>,
54 GetForwardedHeaderLayer<CFConnectingIp>,
55 GetForwardedHeaderLayer<TrueClientIp>,
56 >,
57>;
58
59pub(super) fn http_forwarded_layer(forward: Option<&ForwardKind>) -> HttpForwardedLayer {
62 match forward {
63 None | Some(ForwardKind::HaProxy) => None,
64 Some(ForwardKind::Forwarded) => Some(Either7::A(GetForwardedHeaderLayer::forwarded())),
65 Some(ForwardKind::XForwardedFor) => {
66 Some(Either7::B(GetForwardedHeaderLayer::x_forwarded_for()))
67 }
68 Some(ForwardKind::XClientIp) => {
69 Some(Either7::C(GetForwardedHeaderLayer::<XClientIp>::new()))
70 }
71 Some(ForwardKind::ClientIp) => Some(Either7::D(GetForwardedHeaderLayer::<ClientIp>::new())),
72 Some(ForwardKind::XRealIp) => Some(Either7::E(GetForwardedHeaderLayer::<XRealIp>::new())),
73 Some(ForwardKind::CFConnectingIp) => {
74 Some(Either7::F(GetForwardedHeaderLayer::<CFConnectingIp>::new()))
75 }
76 Some(ForwardKind::TrueClientIp) => {
77 Some(Either7::G(GetForwardedHeaderLayer::<TrueClientIp>::new()))
78 }
79 }
80}