diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 7e1cd85..f38dd99 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -31,12 +31,10 @@ jobs: - name: Run tests default run: cargo test - name: Run tests rustls-tls-manual-roots - run: cargo test --no-default-features rustls-tls-manual-roots + run: cargo test --no-default-features --features rustls-tls-manual-roots - name: Run tests rustls-tls-webpki-roots - run: cargo test --no-default-features rustls-tls-webpki-roots + run: cargo test --no-default-features --features rustls-tls-webpki-roots - name: Run tests native-tls-vendored - run: cargo test --no-default-features native-tls-vendored + run: cargo test --no-default-features --features native-tls-vendored - name: Run tests native-tls - run: cargo test --no-default-features native-tls - - name: Run tests all features - run: cargo test --all-features + run: cargo test --no-default-features --features native-tls \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 95abbc2..cfe5fdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ native-tls = { version = "0.2", optional = true } tokio-rustls = { version = "0.26", optional = true, default-features = false} hyper-rustls = { version = "0.27", optional = true, default-features = false } -rustls-webpki = { version = "0.102", optional = true } rustls-native-certs = { version = "0.7", optional = true } webpki-roots = { version = "0.26", optional = true } headers = "0.4" @@ -45,7 +44,7 @@ default = ["default-tls"] default-tls = ["rustls-tls-native-roots"] native-tls = ["dep:native-tls", "tokio-native-tls", "hyper-tls", "__tls"] native-tls-vendored = ["native-tls", "tokio-native-tls?/vendored"] -rustls-tls-webpki-roots = ["dep:webpki-roots", "__rustls"] +rustls-tls-webpki-roots = ["dep:webpki-roots", "__rustls", "hyper-rustls/webpki-roots"] rustls-tls-native-roots = ["dep:rustls-native-certs", "__rustls", "hyper-rustls/rustls-native-certs"] __tls = [] diff --git a/src/lib.rs b/src/lib.rs index 01fda4c..3e77962 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,9 +139,12 @@ pub(crate) fn io_err>>(e: E) -> io::Error::new(io::ErrorKind::Other, e) } +pub type CustomProxyCallback = + dyn Fn(Option<&str>, Option<&str>, Option) -> bool + Send + Sync; + /// A Custom struct to proxy custom uris #[derive(Clone)] -pub struct Custom(Arc, Option<&str>, Option) -> bool + Send + Sync>); +pub struct Custom(Arc); impl fmt::Debug for Custom { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { @@ -192,7 +195,7 @@ impl Proxy { pub fn new>(intercept: I, uri: Uri) -> Proxy { Proxy { intercept: intercept.into(), - uri: uri, + uri, headers: HeaderMap::new(), force_connect: false, } @@ -313,7 +316,7 @@ impl ProxyConnector { pub fn unsecured(connector: C) -> Self { ProxyConnector { proxies: Vec::new(), - connector: connector, + connector, tls: None, } } @@ -336,7 +339,7 @@ impl ProxyConnector { /// Change proxy connector pub fn with_connector(self, connector: CC) -> ProxyConnector { ProxyConnector { - connector: connector, + connector, proxies: self.proxies, tls: self.tls, } @@ -349,7 +352,7 @@ impl ProxyConnector { } /// Set or unset tls when tunneling - #[cfg(any(feature = "__rustls"))] + #[cfg(feature = "__rustls")] pub fn set_tls(&mut self, tls: Option) { self.tls = tls; } @@ -436,8 +439,9 @@ where }; Box::pin(async move { + // this hack will gone once `try_blocks` will eventually stabilized + #[allow(clippy::never_loop)] loop { - // this hack will gone once `try_blocks` will eventually stabilized let proxy_stream = mtry!(mtry!(connection).await.map_err(io_err)); let tunnel_stream = mtry!(tunnel.with_stream(proxy_stream).await); @@ -459,13 +463,12 @@ where use hyper_util::rt::TokioIo; let server_name = mtry!(ServerName::try_from(host.to_string()).map_err(io_err)); - let tls = TlsConnector::from(tls); let secure_stream = mtry!(tls .connect(server_name, TokioIo::new(tunnel_stream)) .await .map_err(io_err)); - Ok(ProxyStream::Secured(TokioIo::new(secure_stream))) + Ok(ProxyStream::Secured(Box::new(TokioIo::new(secure_stream)))) } #[cfg(not(feature = "__tls",))] diff --git a/src/stream.rs b/src/stream.rs index b0e2c61..5e7fe84 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -25,7 +25,7 @@ pub enum ProxyStream { NoProxy(R), Regular(R), #[cfg(feature = "__tls")] - Secured(TlsStream), + Secured(Box>), } macro_rules! match_fn_pinned { diff --git a/src/tunnel.rs b/src/tunnel.rs index 151dd79..736f9a0 100644 --- a/src/tunnel.rs +++ b/src/tunnel.rs @@ -145,7 +145,7 @@ mod tests { super::new(&host, port, &HeaderMap::new()).with_stream(conn) } - #[cfg_attr(rustfmt, rustfmt_skip)] + #[rustfmt::skip] macro_rules! mock_tunnel { () => {{ mock_tunnel!(