Skip to content

Commit 2c8fdf7

Browse files
committed
feat(main.rs): Add proper basic access log
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent bcd8fca commit 2c8fdf7

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ edition = "2021"
55

66
[dependencies]
77
axum = { version = "0.7.9", features = ["tracing", "multipart", "macros"] }
8-
axum-client-ip = "0.7.0"
98
axum-server = { version = "0.7.1", features = ["rustls", "rustls-pemfile", "tls-rustls"] }
109
azure_blob_uploader = "0.1.4"
1110
azure_storage = "0.21.0"
1211
azure_storage_blobs = "0.21.0"
1312
chksum-hash-sha2-512 = "0.0.1"
13+
chrono = "0.4.39"
1414
clap = { version = "4.5.23", features = ["derive"] }
15-
envy = "0.4.2"
1615
futures = "0.3.31"
1716
futures-util = "0.3.31"
1817
headers = "0.4.0"

src/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ mod storjwt;
1515

1616
use axum::{
1717
body::Body,
18-
extract::{ConnectInfo, DefaultBodyLimit, Multipart, Path, Request},
18+
extract::{ConnectInfo, DefaultBodyLimit, Multipart, Path},
1919
http::{header, Method, StatusCode},
2020
response::IntoResponse,
2121
routing::{get, post},
2222
Router,
2323
};
24-
use axum_client_ip::{InsecureClientIp, SecureClientIp, SecureClientIpSource};
2524
use axum_server::tls_rustls::RustlsConfig;
2625
use clap::Parser;
2726
use headers::HeaderMap;
@@ -138,7 +137,6 @@ async fn main() {
138137
.route("/*filepath", get(ax_get_file))
139138
.layer(
140139
ServiceBuilder::new()
141-
.layer(SecureClientIpSource::ConnectInfo.into_extension())
142140
.layer(DefaultBodyLimit::max(1024 * 1024 * 1024 * 4)),
143141
);
144142

@@ -292,8 +290,16 @@ async fn ax_get_file(
292290
method: Method,
293291
ConnectInfo(remote_addr): ConnectInfo<SocketAddr>,
294292
) -> impl IntoResponse {
295-
//let (mut parts, body) = req.into_parts();
296-
println!("GET file: {} Remote: {:?}", filepath, remote_addr);
293+
let timestamp = std::time::SystemTime::now();
294+
let human_time = chrono::DateTime::<chrono::Utc>::from(timestamp);
295+
// or none
296+
let user_agent = rxheaders.get("User-Agent");
297+
let user_agent_str = match user_agent {
298+
Some(user_agent) => user_agent.to_str().unwrap(),
299+
None => "",
300+
};
301+
// remote_addr human_time method filepath
302+
println!("{:?} {} {} {} {}", remote_addr, human_time, method, filepath, user_agent_str);
297303
let received_file = driver_get_file(filepath.clone());
298304
if !received_file.valid {
299305
return (StatusCode::NOT_FOUND, format!("Not Found: {}", filepath)).into_response();

0 commit comments

Comments
 (0)