-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): adds
HttpInfo
to responses when HttpConnector
is used
- Adds `client::connect::Connected::extra()`, which allows connectors to specify arbitrary custom information about a connected transport. If a connector provides this extra value, it will be set in the `Response` extensions. Closes #1402
- Loading branch information
1 parent
d55b5ef
commit 13d53e1
Showing
5 changed files
with
145 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ use http::uri::Scheme; | |
|
||
use body::{Body, Payload}; | ||
use common::{Exec, lazy as hyper_lazy, Lazy}; | ||
use self::connect::{Connect, Destination}; | ||
use self::connect::{Connect, Connected, Destination}; | ||
use self::pool::{Key as PoolKey, Pool, Poolable, Pooled, Reservation}; | ||
|
||
#[cfg(feature = "runtime")] pub use self::connect::HttpConnector; | ||
|
@@ -290,7 +290,7 @@ where C: Connect + Sync + 'static, | |
// CONNECT always sends origin-form, so check it first... | ||
if req.method() == &Method::CONNECT { | ||
authority_form(req.uri_mut()); | ||
} else if pooled.is_proxied { | ||
} else if pooled.conn_info.is_proxied { | ||
absolute_form(req.uri_mut()); | ||
} else { | ||
origin_form(req.uri_mut()); | ||
|
@@ -305,6 +305,15 @@ where C: Connect + Sync + 'static, | |
let fut = pooled.send_request_retryable(req) | ||
.map_err(ClientError::map_with_reused(pooled.is_reused())); | ||
|
||
// If the Connector included 'extra' info, add to Response... | ||
let extra_info = pooled.conn_info.extra.clone(); | ||
let fut = fut.map(move |mut res| { | ||
if let Some(extra) = extra_info { | ||
extra.set(&mut res); | ||
} | ||
res | ||
}); | ||
|
||
// As of [email protected], there is a race condition in the mpsc | ||
// channel, such that sending when the receiver is closing can | ||
// result in the message being stuck inside the queue. It won't | ||
|
@@ -499,7 +508,7 @@ where C: Connect + Sync + 'static, | |
}) | ||
.map(move |tx| { | ||
pool.pooled(connecting, PoolClient { | ||
is_proxied: connected.is_proxied, | ||
conn_info: connected, | ||
tx: match ver { | ||
Ver::Http1 => PoolTx::Http1(tx), | ||
Ver::Http2 => PoolTx::Http2(tx.into_http2()), | ||
|
@@ -565,7 +574,7 @@ impl Future for ResponseFuture { | |
// FIXME: allow() required due to `impl Trait` leaking types to this lint | ||
#[allow(missing_debug_implementations)] | ||
struct PoolClient<B> { | ||
is_proxied: bool, | ||
conn_info: Connected, | ||
tx: PoolTx<B>, | ||
} | ||
|
||
|
@@ -624,17 +633,17 @@ where | |
match self.tx { | ||
PoolTx::Http1(tx) => { | ||
Reservation::Unique(PoolClient { | ||
is_proxied: self.is_proxied, | ||
conn_info: self.conn_info, | ||
tx: PoolTx::Http1(tx), | ||
}) | ||
}, | ||
PoolTx::Http2(tx) => { | ||
let b = PoolClient { | ||
is_proxied: self.is_proxied, | ||
conn_info: self.conn_info.clone(), | ||
tx: PoolTx::Http2(tx.clone()), | ||
}; | ||
let a = PoolClient { | ||
is_proxied: self.is_proxied, | ||
conn_info: self.conn_info, | ||
tx: PoolTx::Http2(tx), | ||
}; | ||
Reservation::Shared(a, b) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters