-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(auth): Vector does not put the Proxy-Authorization header on the wire (#17353) #17363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -53,10 +53,12 @@ impl HttpError { | |||
| } | ||||
|
|
||||
| pub type HttpClientFuture = <HttpClient as Service<http::Request<Body>>>::Future; | ||||
| type HttpProxyConnector = ProxyConnector<HttpsConnector<HttpConnector>>; | ||||
|
|
||||
| pub struct HttpClient<B = Body> { | ||||
| client: Client<ProxyConnector<HttpsConnector<HttpConnector>>, B>, | ||||
| client: Client<HttpProxyConnector, B>, | ||||
| user_agent: HeaderValue, | ||||
| proxy_connector: HttpProxyConnector, | ||||
| } | ||||
|
|
||||
| impl<B> HttpClient<B> | ||||
|
|
@@ -77,14 +79,18 @@ where | |||
| proxy_config: &ProxyConfig, | ||||
| 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 proxy_connector = build_proxy_connector(tls_settings.into(), proxy_config)?; | ||||
| let client = client_builder.build(proxy_connector.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_connector, | ||||
| }) | ||||
| } | ||||
|
|
||||
| pub fn send( | ||||
|
|
@@ -95,6 +101,7 @@ where | |||
| let _enter = span.enter(); | ||||
|
|
||||
| default_request_headers(&mut request, &self.user_agent); | ||||
| self.maybe_add_proxy_headers(&mut request); | ||||
|
|
||||
| emit!(http_client::AboutToSendHttpRequest { request: &request }); | ||||
|
|
||||
|
|
@@ -135,6 +142,17 @@ where | |||
|
|
||||
| Box::pin(fut) | ||||
| } | ||||
|
|
||||
| fn maybe_add_proxy_headers(&self, request: &mut Request<B>) { | ||||
| if let Some(proxy_headers) = self.proxy_connector.http_headers(request.uri()) { | ||||
| for (k, v) in proxy_headers { | ||||
| let request_headers = request.headers_mut(); | ||||
| if !request_headers.contains_key(k) { | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check if it exists, or can we just insert the new header? HTTP headers can contain multiple values.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going by RFC 7235, https://github.com/hyperium/headers/blob/f01cc90cf8d601a716856bc9d29f47df92b779e4/src/common/authorization.rs#L9 and https://github.com/hyperium/headers/blob/master/src/common/proxy_authorization.rs#L3. My read of RFC 7235 is that it doesn't leave room for >1 sets of credentials in the Authorization and Proxy-Authorization headers. Line 293 in 53e1785
|
||||
| request_headers.insert(k, v.into()); | ||||
| } | ||||
| } | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
| pub fn build_proxy_connector( | ||||
|
|
@@ -216,6 +234,7 @@ impl<B> Clone for HttpClient<B> { | |||
| Self { | ||||
| client: self.client.clone(), | ||||
| user_agent: self.user_agent.clone(), | ||||
| proxy_connector: self.proxy_connector.clone(), | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest moving this out of the loop, to avoid calling it repeatedly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, my oversight.