diff options
author | gennyble <gen@nyble.dev> | 2024-04-13 08:13:39 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-04-13 08:13:39 -0500 |
commit | 826b4f122c175d487a426d97c96bd73f65bc5ea7 (patch) | |
tree | 365a5f890ba6056af6e1226ddda56db21837ea57 /src/main.rs | |
parent | fda7d4474028de0e159d839e080a502b4c463576 (diff) | |
download | awake-826b4f122c175d487a426d97c96bd73f65bc5ea7.tar.gz awake-826b4f122c175d487a426d97c96bd73f65bc5ea7.zip |
Log SessionId and referer
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index b43e463..57c373e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ mod markup; mod settings; mod templated; mod timeparse; +mod util; use std::{os::unix::fs::MetadataExt, str::FromStr}; @@ -25,6 +26,7 @@ use fs::Filesystem; use settings::Settings; use tokio_util::io::ReaderStream; use tracing_subscriber::{prelude::*, EnvFilter}; +use util::{Referer, RemoteIp, SessionId}; use crate::{ fs::{PathResolution, Webpath}, @@ -35,11 +37,8 @@ use crate::{ async fn main() { match std::env::args().nth(1).as_deref() { Some("atomizer") => atomizer::main(), - Some("serve") => /* fallthrough*/ - { - () - } + Some("serve") => (), _ => (), } @@ -74,16 +73,23 @@ async fn main() { axum::serve(listener, app).await.unwrap() } -async fn index_handler(fse: Extension<Filesystem>, se: Extension<Settings>) -> Response { - handler(fse, se, Path(String::from("/"))).await +async fn index_handler( + fse: Extension<Filesystem>, + se: Extension<Settings>, + sid: SessionId, + rfr: Option<Referer>, +) -> Response { + handler(fse, se, sid, rfr, Path(String::from("/"))).await } async fn handler( Extension(fs): Extension<Filesystem>, Extension(settings): Extension<Settings>, + sid: SessionId, + rfr: Option<Referer>, Path(path): Path<String>, ) -> Response { - match falible_handler(fs, settings, path).await { + match falible_handler(fs, settings, sid, rfr, path).await { Ok(resp) => resp, Err(re) => Response::builder() .body(Body::from(re.to_string())) @@ -94,6 +100,8 @@ async fn handler( async fn falible_handler( fs: Filesystem, settings: Settings, + sid: SessionId, + rfr: Option<Referer>, path: String, ) -> Result<Response, RuntimeError> { tracing::debug!("webpath = {path}"); @@ -105,7 +113,14 @@ async fn falible_handler( return Ok(redirect(webpath.as_dir())); } - tracing::info!("serving {webpath}"); + match rfr { + None => { + tracing::info!("[{sid}] serving {webpath}"); + } + Some(referer) => { + tracing::info!("[{sid}] (refer {referer}) serving {webpath}"); + } + } let ext = resolve.filepath.extension().unwrap_or_default(); |