@@ -53,10 +53,12 @@ impl HttpError {
53
53
}
54
54
55
55
pub type HttpClientFuture = <HttpClient as Service < http:: Request < Body > > >:: Future ;
56
+ type HttpProxyConnector = ProxyConnector < HttpsConnector < HttpConnector > > ;
56
57
57
58
pub struct HttpClient < B = Body > {
58
- client : Client < ProxyConnector < HttpsConnector < HttpConnector > > , B > ,
59
+ client : Client < HttpProxyConnector , B > ,
59
60
user_agent : HeaderValue ,
61
+ proxy_connector : HttpProxyConnector ,
60
62
}
61
63
62
64
impl < B > HttpClient < B >
@@ -77,14 +79,18 @@ where
77
79
proxy_config : & ProxyConfig ,
78
80
client_builder : & mut client:: Builder ,
79
81
) -> Result < HttpClient < B > , HttpError > {
80
- let proxy = build_proxy_connector ( tls_settings. into ( ) , proxy_config) ?;
81
- let client = client_builder. build ( proxy ) ;
82
+ let proxy_connector = build_proxy_connector ( tls_settings. into ( ) , proxy_config) ?;
83
+ let client = client_builder. build ( proxy_connector . clone ( ) ) ;
82
84
83
85
let version = crate :: get_version ( ) ;
84
86
let user_agent = HeaderValue :: from_str ( & format ! ( "Vector/{}" , version) )
85
87
. expect ( "Invalid header value for version!" ) ;
86
88
87
- Ok ( HttpClient { client, user_agent } )
89
+ Ok ( HttpClient {
90
+ client,
91
+ user_agent,
92
+ proxy_connector,
93
+ } )
88
94
}
89
95
90
96
pub fn send (
95
101
let _enter = span. enter ( ) ;
96
102
97
103
default_request_headers ( & mut request, & self . user_agent ) ;
104
+ self . maybe_add_proxy_headers ( & mut request) ;
98
105
99
106
emit ! ( http_client:: AboutToSendHttpRequest { request: & request } ) ;
100
107
@@ -135,6 +142,17 @@ where
135
142
136
143
Box :: pin ( fut)
137
144
}
145
+
146
+ fn maybe_add_proxy_headers ( & self , request : & mut Request < B > ) {
147
+ if let Some ( proxy_headers) = self . proxy_connector . http_headers ( request. uri ( ) ) {
148
+ for ( k, v) in proxy_headers {
149
+ let request_headers = request. headers_mut ( ) ;
150
+ if !request_headers. contains_key ( k) {
151
+ request_headers. insert ( k, v. into ( ) ) ;
152
+ }
153
+ }
154
+ }
155
+ }
138
156
}
139
157
140
158
pub fn build_proxy_connector (
@@ -216,6 +234,7 @@ impl<B> Clone for HttpClient<B> {
216
234
Self {
217
235
client : self . client . clone ( ) ,
218
236
user_agent : self . user_agent . clone ( ) ,
237
+ proxy_connector : self . proxy_connector . clone ( ) ,
219
238
}
220
239
}
221
240
}
0 commit comments