more debugging
This commit is contained in:
49
src/main.rs
49
src/main.rs
@@ -13,7 +13,7 @@ use tokio_tungstenite::{
|
|||||||
Message,
|
Message,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{debug, error, info, warn, Level};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "websocket-debug")]
|
#[command(name = "websocket-debug")]
|
||||||
@@ -26,17 +26,23 @@ struct Args {
|
|||||||
/// Bearer token for Authorization header
|
/// Bearer token for Authorization header
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
bearer_token: Option<String>,
|
bearer_token: Option<String>,
|
||||||
|
|
||||||
|
/// Enable debug logging (shows request/response headers)
|
||||||
|
#[arg(long)]
|
||||||
|
debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
|
let log_level = if args.debug { Level::DEBUG } else { Level::INFO };
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_target(false)
|
.with_target(false)
|
||||||
.with_thread_ids(false)
|
.with_thread_ids(false)
|
||||||
|
.with_max_level(log_level)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
let args = Args::parse();
|
|
||||||
|
|
||||||
// Create session directory
|
// Create session directory
|
||||||
let timestamp = Local::now().format("%Y%m%d-%H%M%S");
|
let timestamp = Local::now().format("%Y%m%d-%H%M%S");
|
||||||
let session_dir = PathBuf::from(format!("session-{}", timestamp));
|
let session_dir = PathBuf::from(format!("session-{}", timestamp));
|
||||||
@@ -49,6 +55,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let letter = (b'A' + idx as u8) as char;
|
let letter = (b'A' + idx as u8) as char;
|
||||||
let bearer_token = args.bearer_token.clone();
|
let bearer_token = args.bearer_token.clone();
|
||||||
let url = url.clone();
|
let url = url.clone();
|
||||||
|
let debug_enabled = args.debug;
|
||||||
|
|
||||||
connect_futures.push(async move {
|
connect_futures.push(async move {
|
||||||
let mut request = url
|
let mut request = url
|
||||||
@@ -64,12 +71,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
info!("[{}] Connecting to {}", letter, url);
|
info!("[{}] Connecting to {}", letter, url);
|
||||||
|
|
||||||
let (ws_stream, response) = connect_async_with_config(request, None, false)
|
if debug_enabled {
|
||||||
.await
|
debug!("[{}] Request: {} {}", letter, request.method(), request.uri());
|
||||||
.map_err(|e| format!("[{}] Failed to connect to {}: {}", letter, url, e))?;
|
for (name, value) in request.headers() {
|
||||||
|
debug!("[{}] {}: {}", letter, name, value.to_str().unwrap_or("<binary>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (ws_stream, response) = match connect_async_with_config(request, None, false).await {
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(e) => {
|
||||||
|
if debug_enabled {
|
||||||
|
if let tokio_tungstenite::tungstenite::Error::Http(ref response) = e {
|
||||||
|
debug!("[{}] Error response: {} {}", letter, response.status().as_u16(), response.status().canonical_reason().unwrap_or(""));
|
||||||
|
for (name, value) in response.headers() {
|
||||||
|
debug!("[{}] {}: {}", letter, name, value.to_str().unwrap_or("<binary>"));
|
||||||
|
}
|
||||||
|
if let Some(body) = response.body() {
|
||||||
|
if let Ok(body_str) = std::str::from_utf8(body) {
|
||||||
|
debug!("[{}] Response body: {}", letter, body_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Err(format!("[{}] Failed to connect to {}: {}", letter, url, e));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
info!("[{}] Connected successfully (status: {})", letter, response.status());
|
info!("[{}] Connected successfully (status: {})", letter, response.status());
|
||||||
|
|
||||||
|
if debug_enabled {
|
||||||
|
debug!("[{}] Response: {} {}", letter, response.status().as_u16(), response.status().canonical_reason().unwrap_or(""));
|
||||||
|
for (name, value) in response.headers() {
|
||||||
|
debug!("[{}] {}: {}", letter, name, value.to_str().unwrap_or("<binary>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok::<_, String>((letter, url, ws_stream))
|
Ok::<_, String>((letter, url, ws_stream))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user