Skip to content

Commit

Permalink
add proxy headers
Browse files Browse the repository at this point in the history
  • Loading branch information
syedriko committed May 10, 2023
1 parent 5d3f619 commit 27459d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub type HttpClientFuture = <HttpClient as Service<http::Request<Body>>>::Future
pub struct HttpClient<B = Body> {
client: Client<ProxyConnector<HttpsConnector<HttpConnector>>, B>,
user_agent: HeaderValue,
proxy: ProxyConnector<HttpsConnector<HttpConnector>>,
}

impl<B> HttpClient<B>
Expand All @@ -78,13 +79,13 @@ where
client_builder: &mut client::Builder,
) -> Result<HttpClient<B>, HttpError> {
let proxy = build_proxy_connector(tls_settings.into(), proxy_config)?;
let client = client_builder.build(proxy);
let client = client_builder.build(proxy.clone());

let version = crate::get_version();
let user_agent = HeaderValue::from_str(&format!("Vector/{}", version))
.expect("Invalid header value for version!");

Ok(HttpClient { client, user_agent })
Ok(HttpClient { client, user_agent, proxy })
}

pub fn send(
Expand All @@ -95,6 +96,11 @@ where
let _enter = span.enter();

default_request_headers(&mut request, &self.user_agent);
if let Some(proxy_headers) = self.proxy.http_headers(request.uri()) {
for (k, v) in proxy_headers {
request.headers_mut().insert(k, v.into());
}
}

emit!(http_client::AboutToSendHttpRequest { request: &request });

Expand Down Expand Up @@ -216,6 +222,7 @@ impl<B> Clone for HttpClient<B> {
Self {
client: self.client.clone(),
user_agent: self.user_agent.clone(),
proxy: self.proxy.clone(),
}
}
}
Expand Down

0 comments on commit 27459d0

Please sign in to comment.