Commit a9dcbbc 1 parent 423aa8f commit a9dcbbc Copy full SHA for a9dcbbc
File tree 3 files changed +30
-15
lines changed
3 files changed +30
-15
lines changed Original file line number Diff line number Diff line change @@ -211,16 +211,17 @@ impl<In: Transport> Connector<In> for ConnectProxyConnector {
211
211
212
212
let mut w = TransportAdapter :: new ( transport) ;
213
213
214
- let uri = & details. uri ;
215
- uri. ensure_valid_url ( ) ?;
214
+ // unwrap is ok because run.rs will construct the ConnectionDetails
215
+ // such that CONNECT proxy _must_ have the `proxied` field set.
216
+ let proxied = details. proxied . unwrap ( ) ;
217
+ proxied. ensure_valid_url ( ) ?;
216
218
217
- // All these unwrap() are ok because ensure_valid_uri() above checks them.
218
- let host = uri. host ( ) . unwrap ( ) ;
219
- let port = uri
219
+ let proxied_host = proxied. host ( ) . unwrap ( ) ;
220
+ let proxied_port = proxied
220
221
. port_u16 ( )
221
- . unwrap_or ( uri . scheme ( ) . unwrap ( ) . default_port ( ) . unwrap ( ) ) ;
222
+ . unwrap_or ( proxied . scheme ( ) . unwrap ( ) . default_port ( ) . unwrap ( ) ) ;
222
223
223
- write ! ( w, "CONNECT {}:{} HTTP/1.1\r \n " , host , port ) ?;
224
+ write ! ( w, "CONNECT {}:{} HTTP/1.1\r \n " , proxied_host , proxied_port ) ?;
224
225
write ! ( w, "Host: {}:{}\r \n " , proxy. host( ) , proxy. port( ) ) ?;
225
226
if let Some ( v) = details. config . user_agent ( ) . as_str ( DEFAULT_USER_AGENT ) {
226
227
write ! ( w, "User-Agent: {}\r \n " , v) ?;
Original file line number Diff line number Diff line change @@ -315,23 +315,25 @@ fn add_headers(
315
315
fn connect (
316
316
agent : & Agent ,
317
317
config : & Config ,
318
- uri : & Uri ,
318
+ wanted_uri : & Uri ,
319
319
timings : & mut CallTimings ,
320
320
) -> Result < Connection , Error > {
321
321
// If we're using a CONNECT proxy, we need to resolve that hostname.
322
322
let maybe_connect_uri = config. connect_proxy_uri ( ) ;
323
323
324
- let effective_uri = maybe_connect_uri. unwrap_or ( uri) ;
324
+ let ( uri, proxied) = if let Some ( connect_uri) = maybe_connect_uri {
325
+ ( connect_uri, Some ( wanted_uri) )
326
+ } else {
327
+ ( wanted_uri, None )
328
+ } ;
325
329
326
330
// Before resolving the URI we need to ensure it is a full URI. We
327
331
// cannot make requests with partial uri like "/path".
328
- effective_uri . ensure_valid_url ( ) ?;
332
+ uri . ensure_valid_url ( ) ?;
329
333
330
- let addrs = agent. resolver . resolve (
331
- effective_uri,
332
- config,
333
- timings. next_timeout ( Timeout :: Resolve ) ,
334
- ) ?;
334
+ let addrs = agent
335
+ . resolver
336
+ . resolve ( uri, config, timings. next_timeout ( Timeout :: Resolve ) ) ?;
335
337
336
338
timings. record_time ( Timeout :: Resolve ) ;
337
339
@@ -342,6 +344,7 @@ fn connect(
342
344
config,
343
345
now : timings. now ( ) ,
344
346
timeout : timings. next_timeout ( Timeout :: Connect ) ,
347
+ proxied,
345
348
} ;
346
349
347
350
let connection = agent. pool . connect ( & details, config. max_idle_age ( ) . into ( ) ) ?;
Original file line number Diff line number Diff line change @@ -173,6 +173,9 @@ where
173
173
/// The parameters needed to create a [`Transport`].
174
174
pub struct ConnectionDetails < ' a > {
175
175
/// Full uri that is being requested.
176
+ ///
177
+ /// In the case of CONNECT (HTTP) proxy, this is the URI of the
178
+ /// proxy, and the actual URI is in the `proxied` field.
176
179
pub uri : & ' a Uri ,
177
180
178
181
/// The resolved IP address + port for the uri being requested. See [`Resolver`].
@@ -196,6 +199,14 @@ pub struct ConnectionDetails<'a> {
196
199
/// The next timeout for making the connection.
197
200
// TODO(martin): Make mechanism to lower duration for each step in the connector chain.
198
201
pub timeout : NextTimeout ,
202
+
203
+ /// In case of CONNECT (HTTP) proxy, this is the actual requested
204
+ /// uri that will go through the proxy.
205
+ ///
206
+ /// This ends up in the connect line like `CONNECT host:port HTTP/1.1`.
207
+ ///
208
+ /// For socks proxy it is `None`.
209
+ pub proxied : Option < & ' a Uri > ,
199
210
}
200
211
201
212
impl < ' a > ConnectionDetails < ' a > {
You can’t perform that action at this time.
0 commit comments