Skip to main content

rama_http_types/
proxy.rs

1use crate::{Method, Request, Version, proto::h2::ext::Protocol};
2use rama_core::{
3    extensions::{Extensions, ExtensionsRef as _},
4    matcher::Matcher,
5};
6
7/// Returns true if the provided reuqest is a HTTP Proxy Connect request.
8pub fn is_req_http_proxy_connect<Body>(req: &Request<Body>) -> bool {
9    let http_version = req.version();
10    if http_version <= Version::HTTP_11 {
11        req.method() == Method::CONNECT
12    } else if http_version == Version::HTTP_2 {
13        req.method() == Method::CONNECT && !req.extensions().contains::<Protocol>()
14    } else {
15        false
16    }
17}
18
19#[derive(Debug, Clone, Default)]
20#[non_exhaustive]
21/// [`Matcher`] implementation which uses [`is_req_http_proxy_connect`].
22pub struct HttpProxyConnectMatcher;
23
24impl HttpProxyConnectMatcher {
25    #[inline(always)]
26    #[must_use]
27    /// Create a new [`HttpProxyConnectMatcher`].
28    pub fn new() -> Self {
29        Self
30    }
31}
32
33impl<Body> Matcher<Request<Body>> for HttpProxyConnectMatcher {
34    #[inline(always)]
35    fn matches(&self, _ext: Option<&Extensions>, req: &Request<Body>) -> bool {
36        is_req_http_proxy_connect(req)
37    }
38}