From 2b86691a81078c044962c3821a0b7309317aaed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 3 Mar 2023 12:13:27 +0100 Subject: [PATCH] proxy: set proper user agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of hard-coding "something/1.0.0". Signed-off-by: Fabian Grünbichler --- src/proxy.rs | 5 +++-- src/stream.rs | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/proxy.rs b/src/proxy.rs index 0148904..c614400 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -131,7 +131,7 @@ impl Proxy { }) } - pub(crate) fn connect>(&self, host: S, port: u16) -> String { + pub(crate) fn connect>(&self, host: S, port: u16, user_agent: &str) -> String { let authorization = if self.use_authorization() { let creds = BASE64_STANDARD.encode(format!( "{}:{}", @@ -150,7 +150,7 @@ impl Proxy { format!( "CONNECT {}:{} HTTP/1.1\r\n\ Host: {}:{}\r\n\ -User-Agent: something/1.0.0\r\n\ +User-Agent: {}\r\n\ Proxy-Connection: Keep-Alive\r\n\ {}\ \r\n", @@ -158,6 +158,7 @@ Proxy-Connection: Keep-Alive\r\n\ port, host.as_ref(), port, + user_agent, authorization ) } diff --git a/src/stream.rs b/src/stream.rs index c444b4f..317df21 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -425,7 +425,12 @@ pub(crate) fn connect_host( if proto == Some(Proto::HTTPConnect) { if let Some(ref proxy) = proxy { - write!(stream, "{}", proxy.connect(hostname, port)).unwrap(); + write!( + stream, + "{}", + proxy.connect(hostname, port, &unit.agent.config.user_agent) + ) + .unwrap(); stream.flush()?; let mut proxy_response = Vec::new();