From c09c5e6bbcf79b3984cd4c2cf2f2f5d9e2a4a6af Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Fri, 8 Dec 2023 12:22:24 -0600 Subject: [PATCH 1/2] proxy: add support for proxy authentication with user-specified header values (#2053) --- src/proxy.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/proxy.rs b/src/proxy.rs index 6e1bfcc731..f1d082302a 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -318,6 +318,25 @@ impl Proxy { self } + /// Set the `Proxy-Authorization` header to a specified value. + /// + /// # Example + /// + /// ``` + /// # extern crate reqwest; + /// # use reqwest::header::*; + /// # fn run() -> Result<(), Box> { + /// let proxy = reqwest::Proxy::https("http://localhost:1234")? + /// .custom_http_auth(HeaderValue::from_static("justletmeinalreadyplease")); + /// # Ok(()) + /// # } + /// # fn main() {} + /// ``` + pub fn custom_http_auth(mut self, header_value: HeaderValue) -> Proxy { + self.intercept.set_custom_http_auth(header_value); + self + } + /// Adds a `No Proxy` exclusion list to this Proxy /// /// # Example @@ -619,6 +638,21 @@ impl ProxyScheme { } } + fn set_custom_http_auth(&mut self, header_value: HeaderValue) { + match *self { + ProxyScheme::Http { ref mut auth, .. } => { + *auth = Some(header_value); + } + ProxyScheme::Https { ref mut auth, .. } => { + *auth = Some(header_value); + } + #[cfg(feature = "socks")] + ProxyScheme::Socks5 { .. } => { + panic!("Socks is not supported for this method") + } + } + } + fn if_no_auth(mut self, update: &Option) -> Self { match self { ProxyScheme::Http { ref mut auth, .. } => { @@ -742,6 +776,18 @@ impl Intercept { } } } + + fn set_custom_http_auth(&mut self, header_value: HeaderValue) { + match self { + Intercept::All(ref mut s) + | Intercept::Http(ref mut s) + | Intercept::Https(ref mut s) => s.set_custom_http_auth(header_value), + Intercept::System(_) => unimplemented!(), + Intercept::Custom(ref mut custom) => { + custom.auth = Some(header_value); + } + } + } } #[derive(Clone)] From 1485ce6f754413a81a9673252349f953c1d86e82 Mon Sep 17 00:00:00 2001 From: Andy <112491550+abls@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:51:14 -0800 Subject: [PATCH 2/2] fix: set nodelay correctly to handle when a tls feature is enabled but connection is to an http server (#2062) --- src/connect.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/connect.rs b/src/connect.rs index c171dd18d2..2fdcd56c0d 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -68,6 +68,7 @@ impl Connector { { http.set_local_address(local_addr.into()); http.set_nodelay(nodelay); + Connector { inner: Inner::Http(http), verbose: verbose::OFF, @@ -109,6 +110,7 @@ impl Connector { T: Into>, { http.set_local_address(local_addr.into()); + http.set_nodelay(nodelay); http.enforce_http(false); Connector { @@ -136,6 +138,7 @@ impl Connector { T: Into>, { http.set_local_address(local_addr.into()); + http.set_nodelay(nodelay); http.enforce_http(false); let (tls, tls_proxy) = if proxies.is_empty() {