diff --git a/Cargo.toml b/Cargo.toml index 532c742..3439c5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stoic-quotes" -version = "0.3.8" +version = "0.3.9" edition = "2021" authors = ["Jose Storopoli "] description = "Stoic quotes API backend" diff --git a/src/app.rs b/src/app.rs index 71f7076..d65c075 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,7 +2,7 @@ use crate::pages::{plain_quote, quote, root}; use axum::{http::header::USER_AGENT, http::Request, response::IntoResponse, routing::get, Router}; -use std::{env::current_dir, path::PathBuf}; +use std::{env::current_dir, net::SocketAddr, path::PathBuf}; use tower_http::{services::ServeDir, trace::TraceLayer}; use tracing::info; @@ -11,6 +11,11 @@ use tracing::info; /// return a plain quote. /// Otherwise, return the root page. async fn handle_user_agent(req: Request) -> impl IntoResponse { + let peer_addr = req + .extensions() + .get::() + .map(ToString::to_string) + .unwrap_or_else(|| "unknown".to_string()); let header = Request::headers(&req); let user_agent: String = if let Some(user_agent) = header.get(USER_AGENT) { user_agent.clone().to_str().unwrap().to_string() @@ -18,7 +23,7 @@ async fn handle_user_agent(req: Request) -> impl IntoResponse { "blank".to_string() }; - info!("got user agent: {user_agent}"); + info!("Request from {peer_addr} with User-Agent: {user_agent}"); if user_agent.contains("curl") || user_agent.contains("Wget") { plain_quote().await.into_response()