From 1ff9c7686e12ef7ff47dda2d1fbea9bbc9d72e0c Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sun, 3 Apr 2022 17:46:01 +0200 Subject: [PATCH] Improve some code --- src/utils/network_utils.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utils/network_utils.rs b/src/utils/network_utils.rs index 7b0842e..9e479c9 100644 --- a/src/utils/network_utils.rs +++ b/src/utils/network_utils.rs @@ -25,13 +25,12 @@ pub fn get_remote_ip(req: &HttpRequest, proxy_ip: Option<&str>) -> String { if let Some(proxy) = proxy_ip.as_ref() { if match_ip(proxy, &ip) { if let Some(header) = req.headers().get("X-Forwarded-For") { - let header = header - .to_str() - .unwrap() - .split_once(','); + let header = header.to_str().unwrap(); - if let Some((upstream_ip, _)) = header { + if let Some((upstream_ip, _)) = header.split_once(',') { ip = upstream_ip.to_string(); + } else { + ip = header.to_string(); } } }