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