diff --git a/socktop/src/ws.rs b/socktop/src/ws.rs index 03d966f..70a2db7 100644 --- a/socktop/src/ws.rs +++ b/socktop/src/ws.rs @@ -4,11 +4,10 @@ use flate2::bufread::GzDecoder; use futures_util::{SinkExt, StreamExt}; use rustls::{ClientConfig, RootCertStore}; use rustls_pemfile::Item; -use std::io::{Cursor, Read}; -use std::sync::OnceLock; +use std::io::{Read}; use std::{fs::File, io::BufReader, sync::Arc}; use tokio::net::TcpStream; -use tokio::time::{interval, timeout, Duration}; +use tokio::time::{interval, Duration}; use tokio_tungstenite::{ connect_async, connect_async_tls_with_config, tungstenite::client::IntoClientRequest, tungstenite::Message, Connector, MaybeTlsStream, WebSocketStream, @@ -57,15 +56,6 @@ async fn connect_with_ca(url: &str, ca_path: &str) -> Result bool { - static ON: OnceLock = OnceLock::new(); - *ON.get_or_init(|| { - std::env::var("SOCKTOP_DEBUG") - .map(|v| v != "0") - .unwrap_or(false) - }) -} // Send a "get_metrics" request and await a single JSON reply pub async fn request_metrics(ws: &mut WsStream) -> Option { diff --git a/socktop/tests/ws_probe.rs b/socktop/tests/ws_probe.rs index 93bd6d8..523466a 100644 --- a/socktop/tests/ws_probe.rs +++ b/socktop/tests/ws_probe.rs @@ -15,7 +15,11 @@ async fn probe_ws_endpoints() { } }; - let mut ws = connect(&url).await.expect("connect ws"); + // Optional pinned CA for WSS/self-signed setups + let tls_ca = std::env::var("SOCKTOP_TLS_CA").ok(); + let mut ws = connect(&url, tls_ca.as_deref()) + .await + .expect("connect ws"); // Should get fast metrics quickly let m = request_metrics(&mut ws).await;