From c25de2e313c82687e1280b403eaf764e39b4caeb Mon Sep 17 00:00:00 2001 From: Christof Weickhardt Date: Wed, 13 Apr 2022 04:25:39 +0200 Subject: [PATCH] perf: remove format for X-Forwarded-For header (#25) --- src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d7a0ae8..1d363fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,9 +215,15 @@ fn create_proxied_request( entry.insert(client_ip.to_string().parse()?); } - hyper::header::Entry::Occupied(mut entry) => { - let addr = format!("{}, {}", entry.get().to_str()?, client_ip); - entry.insert(addr.parse()?); + hyper::header::Entry::Occupied(entry) => { + let client_ip_str = client_ip.to_string(); + let mut addr = + String::with_capacity(entry.get().as_bytes().len() + 2 + client_ip_str.len()); + + addr.push_str(std::str::from_utf8(entry.get().as_bytes()).unwrap()); + addr.push(','); + addr.push(' '); + addr.push_str(&client_ip_str); } }