Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
shouya authored Dec 13, 2023
2 parents eec76e6 + 1485ce6 commit f157d38
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -109,6 +110,7 @@ impl Connector {
T: Into<Option<IpAddr>>,
{
http.set_local_address(local_addr.into());
http.set_nodelay(nodelay);
http.enforce_http(false);

Connector {
Expand Down Expand Up @@ -136,6 +138,7 @@ impl Connector {
T: Into<Option<IpAddr>>,
{
http.set_local_address(local_addr.into());
http.set_nodelay(nodelay);
http.enforce_http(false);

let (tls, tls_proxy) = if proxies.is_empty() {
Expand Down
46 changes: 46 additions & 0 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::error::Error>> {
/// 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
Expand Down Expand Up @@ -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<HeaderValue>) -> Self {
match self {
ProxyScheme::Http { ref mut auth, .. } => {
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit f157d38

Please sign in to comment.