From 6f0484f26b5aebc9aebf2de224a4624bd2b915f8 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 27 Apr 2024 21:20:10 +0200 Subject: [PATCH] log user agents --- src/http.rs | 4 ++++ src/main.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/http.rs b/src/http.rs index 8b28807..1fda060 100644 --- a/src/http.rs +++ b/src/http.rs @@ -3,6 +3,7 @@ pub struct Request { pub method: Method, pub path: String, pub host: String, + pub user_agent: String, pub real_ip: Option, pub range: Option, } @@ -54,6 +55,7 @@ impl Request { let mut host = None; let mut range = None; let mut real_ip = None; + let mut user_agent = String::new(); for line in lines { if line.is_empty() { break; @@ -64,6 +66,7 @@ impl Request { "host" => host = Some(value.to_owned()), "range" => range = RequestRange::parse(value), "x-real-ip" => real_ip = Some(value.to_owned()), + "user-agent" => user_agent = value.to_owned(), _ => (), } } @@ -88,6 +91,7 @@ impl Request { host, real_ip, range, + user_agent, }) } } diff --git a/src/main.rs b/src/main.rs index f8925b1..fea9a6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,6 +105,7 @@ fn handle_request(request: &str, stream: &mut TcpStream) -> bool { if let Some(request) = request { let client_ip = format!("{socket_addr}"); let client_ip = request.real_ip.as_ref().unwrap_or(&client_ip); + println!("[{client_ip}] {}", request.user_agent); println!("[{client_ip}] {} {}", request.method, request.path); let head_only = request.method == Method::Head; let path = request.path.clone();