From 82fcd95fd3da8e2f44c6988e05bfcfb5347ce123 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 23 Jan 2021 08:19:10 +0100 Subject: [PATCH] Start to extract remote IP address --- src/controllers/server.rs | 9 +++++++-- src/data/http_request_handler.rs | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/controllers/server.rs b/src/controllers/server.rs index 91e1d40..9739379 100644 --- a/src/controllers/server.rs +++ b/src/controllers/server.rs @@ -254,7 +254,8 @@ async fn process_request(custom_req: CustomRequest) -> HttpResponse { request.internal_error(e).unwrap_err(); } - println!("{} - {} - {}", + println!("{} - {} - {} - {}", + request.remote_ip(), request.response_status_code(), request.request_path(), err_msg @@ -267,7 +268,11 @@ async fn process_request(custom_req: CustomRequest) -> HttpResponse { request.success("Success").unwrap() } - println!("{} - {}", request.response_status_code(), request.request_path()); + println!("{} - {} - {}", + request.remote_ip(), + request.response_status_code(), + request.request_path() + ); } } diff --git a/src/data/http_request_handler.rs b/src/data/http_request_handler.rs index c991929..00bef3b 100644 --- a/src/data/http_request_handler.rs +++ b/src/data/http_request_handler.rs @@ -192,6 +192,11 @@ impl HttpRequestHandler { self.client.as_ref().unwrap() } + /// Get the remote IP address + pub fn remote_ip(&self) -> String { + self.request.peer_addr().unwrap().ip().to_string() + } + /// Check if a POST parameter was present in the request or not pub fn has_post_parameter(&self, name: &str) -> bool { self.body.contains_key(name) @@ -690,7 +695,7 @@ impl HttpRequestHandler { let info = self.ok_or_not_found( custom_emojies_helper::get_single(emoji_id), - "Requested emoji not found!" + "Requested emoji not found!", )?; if &info.user_id != self.user_id_ref()? {