From d4c5459f2319941693f5c2009260f8a384b20575 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Wed, 10 Apr 2024 08:51:10 +1200 Subject: [PATCH] Capture and log the Origin header (like the User-Agent header) --- chorus-bin/src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/chorus-bin/src/main.rs b/chorus-bin/src/main.rs index 12a0796..a71adc4 100644 --- a/chorus-bin/src/main.rs +++ b/chorus-bin/src/main.rs @@ -304,7 +304,12 @@ async fn handle_http_request( ) -> Result, Error> { let ua = match request.headers().get("user-agent") { Some(ua) => ua.to_str().unwrap_or("NON-UTF8-HEADER").to_owned(), - None => "".to_owned(), + None => "(no user-agent)".to_owned(), + }; + + let origin = match request.headers().get("origin") { + Some(o) => o.to_str().unwrap_or("NON-UTF8-HEADER").to_owned(), + None => "(no origin)".to_owned(), }; if hyper_tungstenite::is_upgrade_request(&request) { @@ -340,10 +345,11 @@ async fn handle_http_request( // as server messages log::info!( target: "Server", - "{}: TOTAL={}, New Connection: {}", + "{}: TOTAL={}, New Connection: {}, {}", peer, old_num_websockets + 1, - ua + origin, + ua, ); // Everybody gets a ban on disconnect to prevent rapid reconnection