Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::time::Duration;
use futures_util::future::{self, Either, FutureExt, TryFutureExt};
use http::uri::Scheme;
use hyper::client::conn::TrySendError as ConnTrySendError;
use hyper::header::{HeaderValue, HOST};
use hyper::header::{HeaderValue, HOST, PROXY_AUTHORIZATION};
use hyper::rt::Timer;
use hyper::{body::Body, Method, Request, Response, Uri, Version};
use tracing::{debug, trace, warn};
Expand Down Expand Up @@ -315,6 +315,11 @@ where
authority_form(req.uri_mut());
} else if pooled.conn_info.is_proxied {
absolute_form(req.uri_mut());
if let Some(proxy_auth) = &pooled.conn_info.proxy_basic_auth {
req.headers_mut()
.entry(PROXY_AUTHORIZATION)
.or_insert_with(|| proxy_auth.clone());
}
} else {
origin_form(req.uri_mut());
}
Expand Down
16 changes: 15 additions & 1 deletion src/client/legacy/connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use std::{
},
};

use ::http::Extensions;
use ::http::{Extensions, HeaderValue};

#[cfg(feature = "tokio")]
pub use self::http::{HttpConnector, HttpInfo};
Expand Down Expand Up @@ -101,6 +101,7 @@ pub trait Connection {
pub struct Connected {
pub(super) alpn: Alpn,
pub(super) is_proxied: bool,
pub(crate) proxy_basic_auth: Option<HeaderValue>,
pub(super) extra: Option<Extra>,
pub(super) poisoned: PoisonPill,
}
Expand Down Expand Up @@ -151,6 +152,7 @@ impl Connected {
Connected {
alpn: Alpn::None,
is_proxied: false,
proxy_basic_auth: None,
extra: None,
poisoned: PoisonPill::healthy(),
}
Expand Down Expand Up @@ -184,6 +186,17 @@ impl Connected {
self.is_proxied
}

/// Set the Proxy-Authorization header value for HTTP Proxy authentication.
pub fn proxy_basic_auth(mut self, auth: HeaderValue) -> Connected {
self.proxy_basic_auth = Some(auth);
self
}

/// Get the Proxy-Authorization header value for HTTP Proxy authentication.
pub fn get_proxy_basic_auth(&self) -> Option<&HeaderValue> {
self.proxy_basic_auth.as_ref()
}

/// Set extra connection information to be set in the extensions of every `Response`.
pub fn extra<T: Clone + Send + Sync + 'static>(mut self, extra: T) -> Connected {
if let Some(prev) = self.extra {
Expand Down Expand Up @@ -228,6 +241,7 @@ impl Connected {
Connected {
alpn: self.alpn,
is_proxied: self.is_proxied,
proxy_basic_auth: self.proxy_basic_auth.clone(),
extra: self.extra.clone(),
poisoned: self.poisoned.clone(),
}
Expand Down