diff --git a/src/client/legacy/client.rs b/src/client/legacy/client.rs index 67cd222..2e608f5 100644 --- a/src/client/legacy/client.rs +++ b/src/client/legacy/client.rs @@ -284,9 +284,9 @@ where // it returns an error, there's not much else to retry .map_err(TrySendError::Nope)?; - req.extensions_mut() - .get_mut::() - .map(|conn| conn.set(&pooled.conn_info)); + if let Some(conn) = req.extensions_mut().get_mut::() { + conn.set(&pooled.conn_info); + } if pooled.is_http1() { if req.version() == Version::HTTP_2 { @@ -301,7 +301,7 @@ where req.headers_mut().entry(HOST).or_insert_with(|| { let hostname = uri.host().expect("authority implies host"); if let Some(port) = get_non_default_port(&uri) { - let s = format!("{}:{}", hostname, port); + let s = format!("{hostname}:{port}"); HeaderValue::from_str(&s) } else { HeaderValue::from_str(hostname) diff --git a/src/client/legacy/connect/capture.rs b/src/client/legacy/connect/capture.rs index fdce6bf..b31b643 100644 --- a/src/client/legacy/connect/capture.rs +++ b/src/client/legacy/connect/capture.rs @@ -131,22 +131,18 @@ mod test { "connection has not been set" ); tx.set(&Connected::new().proxy(true)); - assert_eq!( - rx.connection_metadata() - .as_ref() - .expect("connected should be set") - .is_proxied(), - true - ); + assert!(rx + .connection_metadata() + .as_ref() + .expect("connected should be set") + .is_proxied()); // ensure it can be called multiple times - assert_eq!( - rx.connection_metadata() - .as_ref() - .expect("connected should be set") - .is_proxied(), - true - ); + assert!(rx + .connection_metadata() + .as_ref() + .expect("connected should be set") + .is_proxied()); } #[tokio::test] @@ -157,24 +153,22 @@ mod test { "connection has not been set" ); let test_task = tokio::spawn(async move { - assert_eq!( - rx.wait_for_connection_metadata() - .await - .as_ref() - .expect("connection should be set") - .is_proxied(), - true - ); + assert!(rx + .wait_for_connection_metadata() + .await + .as_ref() + .expect("connection should be set") + .is_proxied()); // can be awaited multiple times assert!( rx.wait_for_connection_metadata().await.is_some(), "should be awaitable multiple times" ); - assert_eq!(rx.connection_metadata().is_some(), true); + assert!(rx.connection_metadata().is_some()); }); // can't be finished, we haven't set the connection yet - assert_eq!(test_task.is_finished(), false); + assert!(!test_task.is_finished()); tx.set(&Connected::new().proxy(true)); assert!(test_task.await.is_ok()); diff --git a/src/client/legacy/connect/dns.rs b/src/client/legacy/connect/dns.rs index 844c75a..b6d3ddd 100644 --- a/src/client/legacy/connect/dns.rs +++ b/src/client/legacy/connect/dns.rs @@ -143,7 +143,7 @@ impl Future for GaiFuture { if join_err.is_cancelled() { Err(io::Error::new(io::ErrorKind::Interrupted, join_err)) } else { - panic!("gai background task failed: {:?}", join_err) + panic!("gai background task failed: {join_err:?}") } } }) diff --git a/src/client/legacy/connect/http.rs b/src/client/legacy/connect/http.rs index 7a73a55..4e269f1 100644 --- a/src/client/legacy/connect/http.rs +++ b/src/client/legacy/connect/http.rs @@ -692,7 +692,7 @@ impl fmt::Display for ConnectError { f.write_str(&self.msg)?; if let Some(ref cause) = self.cause { - write!(f, ": {}", cause)?; + write!(f, ": {cause}")?; } Ok(()) @@ -1100,7 +1100,7 @@ mod tests { let (bind_ip_v4, bind_ip_v6) = get_local_ips(); let server4 = TcpListener::bind("127.0.0.1:0").unwrap(); let port = server4.local_addr().unwrap().port(); - let server6 = TcpListener::bind(&format!("[::1]:{}", port)).unwrap(); + let server6 = TcpListener::bind(format!("[::1]:{port}")).unwrap(); let assert_client_ip = |dst: String, server: TcpListener, expected_ip: IpAddr| async move { let mut connector = HttpConnector::new(); @@ -1120,11 +1120,11 @@ mod tests { }; if let Some(ip) = bind_ip_v4 { - assert_client_ip(format!("http://127.0.0.1:{}", port), server4, ip.into()).await; + assert_client_ip(format!("http://127.0.0.1:{port}"), server4, ip.into()).await; } if let Some(ip) = bind_ip_v6 { - assert_client_ip(format!("http://[::1]:{}", port), server6, ip.into()).await; + assert_client_ip(format!("http://[::1]:{port}"), server6, ip.into()).await; } } @@ -1141,7 +1141,7 @@ mod tests { let server4 = TcpListener::bind("127.0.0.1:0").unwrap(); let port = server4.local_addr().unwrap().port(); - let server6 = TcpListener::bind(&format!("[::1]:{}", port)).unwrap(); + let server6 = TcpListener::bind(format!("[::1]:{port}")).unwrap(); let assert_interface_name = |dst: String, @@ -1164,14 +1164,14 @@ mod tests { }; assert_interface_name( - format!("http://127.0.0.1:{}", port), + format!("http://127.0.0.1:{port}"), server4, interface.clone(), interface.clone(), ) .await; assert_interface_name( - format!("http://[::1]:{}", port), + format!("http://[::1]:{port}"), server6, interface.clone(), interface.clone(), @@ -1191,7 +1191,7 @@ mod tests { let server4 = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = server4.local_addr().unwrap(); - let _server6 = TcpListener::bind(&format!("[::1]:{}", addr.port())).unwrap(); + let _server6 = TcpListener::bind(format!("[::1]:{}", addr.port())).unwrap(); let rt = tokio::runtime::Builder::new_current_thread() .enable_all() .build() @@ -1295,7 +1295,7 @@ mod tests { .block_on(async move { let addrs = hosts .iter() - .map(|host| (host.clone(), addr.port()).into()) + .map(|host| (*host, addr.port()).into()) .collect(); let cfg = Config { local_address_ipv4: None, @@ -1402,8 +1402,10 @@ mod tests { #[test] fn tcp_keepalive_time_config() { - let mut kac = TcpKeepaliveConfig::default(); - kac.time = Some(Duration::from_secs(60)); + let kac = TcpKeepaliveConfig { + time: Some(Duration::from_secs(60)), + ..Default::default() + }; if let Some(tcp_keepalive) = kac.into_tcpkeepalive() { assert!(format!("{tcp_keepalive:?}").contains("time: Some(60s)")); } else { @@ -1414,8 +1416,10 @@ mod tests { #[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))] #[test] fn tcp_keepalive_interval_config() { - let mut kac = TcpKeepaliveConfig::default(); - kac.interval = Some(Duration::from_secs(1)); + let kac = TcpKeepaliveConfig { + interval: Some(Duration::from_secs(1)), + ..Default::default() + }; if let Some(tcp_keepalive) = kac.into_tcpkeepalive() { assert!(format!("{tcp_keepalive:?}").contains("interval: Some(1s)")); } else { @@ -1431,8 +1435,10 @@ mod tests { )))] #[test] fn tcp_keepalive_retries_config() { - let mut kac = TcpKeepaliveConfig::default(); - kac.retries = Some(3); + let kac = TcpKeepaliveConfig { + retries: Some(3), + ..Default::default() + }; if let Some(tcp_keepalive) = kac.into_tcpkeepalive() { assert!(format!("{tcp_keepalive:?}").contains("retries: Some(3)")); } else { diff --git a/src/client/legacy/connect/proxy/socks/mod.rs b/src/client/legacy/connect/proxy/socks/mod.rs index 20eac57..d6077b9 100644 --- a/src/client/legacy/connect/proxy/socks/mod.rs +++ b/src/client/legacy/connect/proxy/socks/mod.rs @@ -50,7 +50,7 @@ where match M::try_from(buf) { Err(ParsingError::Incomplete) => { if n == 0 { - if buf.spare_capacity_mut().len() == 0 { + if buf.spare_capacity_mut().is_empty() { return Err(SocksError::Parsing(ParsingError::WouldOverflow)); } else { return Err(std::io::Error::new( diff --git a/src/client/legacy/connect/proxy/socks/v4/messages.rs b/src/client/legacy/connect/proxy/socks/v4/messages.rs index c29d677..bec8d08 100644 --- a/src/client/legacy/connect/proxy/socks/v4/messages.rs +++ b/src/client/legacy/connect/proxy/socks/v4/messages.rs @@ -101,7 +101,7 @@ impl TryFrom<&mut BytesMut> for Response { SocketAddrV4::new(ip.into(), port) }; - return Ok(Self(status)); + Ok(Self(status)) } } diff --git a/src/client/legacy/connect/proxy/socks/v4/mod.rs b/src/client/legacy/connect/proxy/socks/v4/mod.rs index b99bac5..bee7e6d 100644 --- a/src/client/legacy/connect/proxy/socks/v4/mod.rs +++ b/src/client/legacy/connect/proxy/socks/v4/mod.rs @@ -97,7 +97,7 @@ impl SocksConfig { { let address = match host.parse::() { Ok(IpAddr::V6(_)) => return Err(SocksV4Error::IpV6.into()), - Ok(IpAddr::V4(ip)) => Address::Socket(SocketAddrV4::new(ip.into(), port)), + Ok(IpAddr::V4(ip)) => Address::Socket(SocketAddrV4::new(ip, port)), Err(_) => { if self.local_dns { (host, port) diff --git a/src/client/legacy/connect/proxy/socks/v5/mod.rs b/src/client/legacy/connect/proxy/socks/v5/mod.rs index 890a532..caf2446 100644 --- a/src/client/legacy/connect/proxy/socks/v5/mod.rs +++ b/src/client/legacy/connect/proxy/socks/v5/mod.rs @@ -199,18 +199,16 @@ impl SocksConfig { } else { state = State::ReadingProxyRes; } + } else if res.0 == AuthMethod::UserPass { + state = State::SendingAuthReq; } else { - if res.0 == AuthMethod::UserPass { - state = State::SendingAuthReq; - } else { - state = State::SendingProxyReq; - } + state = State::SendingProxyReq; } } State::SendingAuthReq => { let (user, pass) = self.proxy_auth.as_ref().unwrap(); - let req = AuthenticationReq(&user, &pass); + let req = AuthenticationReq(user, pass); let start = send_buf.len(); req.write_to_buf(&mut send_buf)?; diff --git a/src/client/legacy/pool.rs b/src/client/legacy/pool.rs index d7f5d20..727f54b 100644 --- a/src/client/legacy/pool.rs +++ b/src/client/legacy/pool.rs @@ -878,7 +878,7 @@ mod tests { } fn pool_no_timer() -> Pool { - pool_max_idle_no_timer(::std::usize::MAX) + pool_max_idle_no_timer(usize::MAX) } fn pool_max_idle_no_timer(max_idle: usize) -> Pool { @@ -959,7 +959,7 @@ mod tests { let poll_once = PollOnce(&mut checkout); // checkout.await should clean out the expired poll_once.await; - assert!(pool.locked().idle.get(&key).is_none()); + assert!(!pool.locked().idle.contains_key(&key)); } #[test] @@ -983,7 +983,7 @@ mod tests { let pool = Pool::new( super::Config { idle_timeout: Some(Duration::from_millis(10)), - max_idle_per_host: std::usize::MAX, + max_idle_per_host: usize::MAX, }, TokioExecutor::new(), Some(TokioTimer::new()), @@ -1005,7 +1005,7 @@ mod tests { // Yield so the Interval can reap... tokio::task::yield_now().await; - assert!(pool.locked().idle.get(&key).is_none()); + assert!(!pool.locked().idle.contains_key(&key)); } #[tokio::test] @@ -1052,7 +1052,7 @@ mod tests { assert_eq!(pool.locked().waiters.get(&key).unwrap().len(), 1); drop(checkout2); - assert!(pool.locked().waiters.get(&key).is_none()); + assert!(!pool.locked().waiters.contains_key(&key)); } #[derive(Debug)] diff --git a/src/client/proxy/matcher.rs b/src/client/proxy/matcher.rs index f7ad897..6f1bf17 100644 --- a/src/client/proxy/matcher.rs +++ b/src/client/proxy/matcher.rs @@ -280,10 +280,10 @@ impl Builder { /// The rules are as follows: /// * Entries are expected to be comma-separated (whitespace between entries is ignored) /// * IP addresses (both IPv4 and IPv6) are allowed, as are optional subnet masks (by adding /size, - /// for example "`192.168.1.0/24`"). + /// for example "`192.168.1.0/24`"). /// * An entry "`*`" matches all hostnames (this is the only wildcard allowed) /// * Any other entry is considered a domain name (and may contain a leading dot, for example `google.com` - /// and `.google.com` are equivalent) and would match both that domain AND all subdomains. + /// and `.google.com` are equivalent) and would match both that domain AND all subdomains. /// /// For example, if `"NO_PROXY=google.com, 192.168.1.0/24"` was set, all of the following would match /// (and therefore would bypass the proxy): @@ -422,10 +422,10 @@ impl NoProxy { /// * If neither environment variable is set, `None` is returned /// * Entries are expected to be comma-separated (whitespace between entries is ignored) /// * IP addresses (both IPv4 and IPv6) are allowed, as are optional subnet masks (by adding /size, - /// for example "`192.168.1.0/24`"). + /// for example "`192.168.1.0/24`"). /// * An entry "`*`" matches all hostnames (this is the only wildcard allowed) /// * Any other entry is considered a domain name (and may contain a leading dot, for example `google.com` - /// and `.google.com` are equivalent) and would match both that domain AND all subdomains. + /// and `.google.com` are equivalent) and would match both that domain AND all subdomains. /// /// For example, if `"NO_PROXY=google.com, 192.168.1.0/24"` was set, all of the following would match /// (and therefore would bypass the proxy): @@ -729,7 +729,7 @@ mod tests { ]; for host in &should_not_match { - assert!(!no_proxy.contains(host), "should not contain {:?}", host); + assert!(!no_proxy.contains(host), "should not contain {host:?}"); } let should_match = [ @@ -752,7 +752,7 @@ mod tests { ]; for host in &should_match { - assert!(no_proxy.contains(host), "should contain {:?}", host); + assert!(no_proxy.contains(host), "should contain {host:?}"); } } @@ -763,7 +763,7 @@ mod tests { }.build()}); } - fn intercept<'a>(p: &'a Matcher, u: &str) -> Intercept { + fn intercept(p: &Matcher, u: &str) -> Intercept { p.intercept(&u.parse().unwrap()).unwrap() } diff --git a/src/service/oneshot.rs b/src/service/oneshot.rs index 4584304..2cc3e6e 100644 --- a/src/service/oneshot.rs +++ b/src/service/oneshot.rs @@ -47,7 +47,7 @@ where let this = self.as_mut().project(); match this { OneshotProj::NotReady { svc, req } => { - let _ = ready!(svc.poll_ready(cx))?; + ready!(svc.poll_ready(cx))?; let fut = svc.call(req.take().expect("already called")); self.set(Oneshot::Called { fut }); } diff --git a/tests/legacy_client.rs b/tests/legacy_client.rs index 95983df..97a0aca 100644 --- a/tests/legacy_client.rs +++ b/tests/legacy_client.rs @@ -70,7 +70,7 @@ fn drop_body_before_eof_closes_connection() { }); let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let res = client.request(req).map_ok(move |res| { @@ -110,9 +110,8 @@ async fn drop_client_closes_idle_connections() { // prevent this thread from closing until end of test, so the connection // stays open and idle until Client is dropped - match sock.read(&mut buf).await { - Ok(n) => assert_eq!(n, 0), - Err(_) => (), + if let Ok(n) = sock.read(&mut buf).await { + assert_eq!(n, 0); } }); @@ -122,7 +121,7 @@ async fn drop_client_closes_idle_connections() { )); let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let res = client.request(req).map_ok(move |res| { @@ -184,7 +183,7 @@ async fn drop_response_future_closes_in_progress_connection() { ); let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); client.request(req).map(|_| unreachable!()) @@ -237,7 +236,7 @@ async fn drop_response_body_closes_in_progress_connection() { ); let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); // notably, haven't read body yet @@ -292,7 +291,7 @@ async fn no_keep_alive_closes_connection() { )); let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let res = client.request(req).map_ok(move |res| { @@ -338,7 +337,7 @@ async fn socket_disconnect_closes_idle_conn() { )); let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let res = client.request(req).map_ok(move |res| { @@ -418,7 +417,7 @@ fn client_keep_alive_0() { let rx = rx1; let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let res = client.request(req); @@ -432,7 +431,7 @@ fn client_keep_alive_0() { let rx = rx2; let req = Request::builder() - .uri(&*format!("http://{}/b", addr)) + .uri(&*format!("http://{addr}/b")) .body(Empty::::new()) .unwrap(); let res = client.request(req); @@ -490,7 +489,7 @@ fn client_keep_alive_extra_body() { let rx = rx1; let req = Request::builder() .method("HEAD") - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let res = client.request(req); @@ -500,7 +499,7 @@ fn client_keep_alive_extra_body() { let rx = rx2; let req = Request::builder() - .uri(&*format!("http://{}/b", addr)) + .uri(&*format!("http://{addr}/b")) .body(Empty::::new()) .unwrap(); let res = client.request(req); @@ -555,7 +554,7 @@ async fn client_keep_alive_when_response_before_request_body_ends() { let req = Request::builder() .method("POST") - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(StreamBody::new(delayed_body)) .unwrap(); let res = client.request(req).map_ok(move |res| { @@ -630,7 +629,7 @@ async fn client_keep_alive_eager_when_chunked() { let rx = rx1; let req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let fut = client.request(req); @@ -650,7 +649,7 @@ async fn client_keep_alive_eager_when_chunked() { let rx = rx2; let req = Request::builder() - .uri(&*format!("http://{}/b", addr)) + .uri(&*format!("http://{addr}/b")) .body(Empty::::new()) .unwrap(); let fut = client.request(req); @@ -684,10 +683,7 @@ fn connect_proxy_sends_absolute_uri() { .unwrap(); let mut buf = [0; 4096]; let n = sock.read(&mut buf).expect("read 1"); - let expected = format!( - "GET http://{addr}/foo/bar HTTP/1.1\r\nhost: {addr}\r\n\r\n", - addr = addr - ); + let expected = format!("GET http://{addr}/foo/bar HTTP/1.1\r\nhost: {addr}\r\n\r\n"); assert_eq!(s(&buf[..n]), expected); sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n") @@ -697,7 +693,7 @@ fn connect_proxy_sends_absolute_uri() { let rx = rx1; let req = Request::builder() - .uri(&*format!("http://{}/foo/bar", addr)) + .uri(&*format!("http://{addr}/foo/bar")) .body(Empty::::new()) .unwrap(); let res = client.request(req); @@ -724,10 +720,7 @@ fn connect_proxy_http_connect_sends_authority_form() { .unwrap(); let mut buf = [0; 4096]; let n = sock.read(&mut buf).expect("read 1"); - let expected = format!( - "CONNECT {addr} HTTP/1.1\r\nhost: {addr}\r\n\r\n", - addr = addr - ); + let expected = format!("CONNECT {addr} HTTP/1.1\r\nhost: {addr}\r\n\r\n"); assert_eq!(s(&buf[..n]), expected); sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n") @@ -738,7 +731,7 @@ fn connect_proxy_http_connect_sends_authority_form() { let rx = rx1; let req = Request::builder() .method("CONNECT") - .uri(&*format!("http://{}/useless/path", addr)) + .uri(&*format!("http://{addr}/useless/path")) .body(Empty::::new()) .unwrap(); let res = client.request(req); @@ -787,7 +780,7 @@ fn client_upgrade() { let req = Request::builder() .method("GET") - .uri(&*format!("http://{}/up", addr)) + .uri(&*format!("http://{addr}/up")) .body(Empty::::new()) .unwrap(); @@ -832,7 +825,7 @@ fn client_http2_upgrade() { let mut builder = hyper_util::server::conn::auto::Builder::new(TokioExecutor::new()); // IMPORTANT: This is required to advertise our support for HTTP/2 websockets to the client. builder.http2().enable_connect_protocol(); - let _ = builder + builder .serve_connection_with_upgrades( stream, service_fn(|req| async move { @@ -867,7 +860,7 @@ fn client_http2_upgrade() { let req = Request::builder() .method(Method::CONNECT) - .uri(&*format!("http://{}/up", addr)) + .uri(&*format!("http://{addr}/up")) .header(http::header::SEC_WEBSOCKET_VERSION, "13") .version(Version::HTTP_2) .extension(hyper::ext::Protocol::from_static("websocket")) @@ -911,7 +904,7 @@ fn alpn_h2() { rt.spawn(async move { let (stream, _) = listener.accept().await.expect("accept"); let stream = TokioIo::new(stream); - let _ = hyper::server::conn::http2::Builder::new(TokioExecutor::new()) + hyper::server::conn::http2::Builder::new(TokioExecutor::new()) .serve_connection( stream, service_fn(|req| async move { @@ -925,9 +918,7 @@ fn alpn_h2() { assert_eq!(connects.load(Ordering::SeqCst), 0); - let url = format!("http://{}/a", addr) - .parse::<::hyper::Uri>() - .unwrap(); + let url = format!("http://{addr}/a").parse::<::hyper::Uri>().unwrap(); let res1 = client.get(url.clone()); let res2 = client.get(url.clone()); let res3 = client.get(url.clone()); @@ -982,7 +973,7 @@ fn capture_connection_on_client() { .expect("write 1"); }); let mut req = Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap(); let captured_conn = capture_connection(&mut req); @@ -1028,7 +1019,7 @@ fn connection_poisoning() { }); let make_request = || { Request::builder() - .uri(&*format!("http://{}/a", addr)) + .uri(&*format!("http://{addr}/a")) .body(Empty::::new()) .unwrap() }; diff --git a/tests/proxy.rs b/tests/proxy.rs index e2096ff..95f4bc2 100644 --- a/tests/proxy.rs +++ b/tests/proxy.rs @@ -11,7 +11,7 @@ async fn test_tunnel_works() { let tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let addr = tcp.local_addr().expect("local_addr"); - let proxy_dst = format!("http://{}", addr).parse().expect("uri"); + let proxy_dst = format!("http://{addr}").parse().expect("uri"); let mut connector = Tunnel::new(proxy_dst, HttpConnector::new()); let t1 = tokio::spawn(async move { let _conn = connector