Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha committed May 26, 2024
1 parent 51047db commit 53e8b08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = []
Expand Down
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ pub(crate) fn io_err<E: Into<Box<dyn std::error::Error + Send + Sync>>>(e: E) ->
io::Error::new(io::ErrorKind::Other, e)
}

pub type CustomProxyCallback =
dyn Fn(Option<&str>, Option<&str>, Option<u16>) -> bool + Send + Sync;

/// A Custom struct to proxy custom uris
#[derive(Clone)]
pub struct Custom(Arc<dyn Fn(Option<&str>, Option<&str>, Option<u16>) -> bool + Send + Sync>);
pub struct Custom(Arc<CustomProxyCallback>);

impl fmt::Debug for Custom {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
Expand Down Expand Up @@ -192,7 +195,7 @@ impl Proxy {
pub fn new<I: Into<Intercept>>(intercept: I, uri: Uri) -> Proxy {
Proxy {
intercept: intercept.into(),
uri: uri,
uri,
headers: HeaderMap::new(),
force_connect: false,
}
Expand Down Expand Up @@ -313,7 +316,7 @@ impl<C> ProxyConnector<C> {
pub fn unsecured(connector: C) -> Self {
ProxyConnector {
proxies: Vec::new(),
connector: connector,
connector,
tls: None,
}
}
Expand All @@ -336,7 +339,7 @@ impl<C> ProxyConnector<C> {
/// Change proxy connector
pub fn with_connector<CC>(self, connector: CC) -> ProxyConnector<CC> {
ProxyConnector {
connector: connector,
connector,
proxies: self.proxies,
tls: self.tls,
}
Expand All @@ -349,7 +352,7 @@ impl<C> ProxyConnector<C> {
}

/// Set or unset tls when tunneling
#[cfg(any(feature = "__rustls"))]
#[cfg(feature = "__rustls")]
pub fn set_tls(&mut self, tls: Option<TlsConnector>) {
self.tls = tls;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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",))]
Expand Down
2 changes: 1 addition & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum ProxyStream<R> {
NoProxy(R),
Regular(R),
#[cfg(feature = "__tls")]
Secured(TlsStream<R>),
Secured(Box<TlsStream<R>>),
}

macro_rules! match_fn_pinned {
Expand Down
2 changes: 1 addition & 1 deletion src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 53e8b08

Please sign in to comment.