Skip to content

Commit

Permalink
feat(client): introduce lower-level Connection API
Browse files Browse the repository at this point in the history
Closes #1449
  • Loading branch information
seanmonstar committed Mar 8, 2018
1 parent eb15c66 commit 192ce09
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ where
/// # }
/// # fn main() {}
/// ```
pub fn send_request(&mut self, mut req: Request<B>) -> ResponseFuture {
pub fn send_request(&mut self, req: Request<B>) -> ResponseFuture {
/* TODO?
// The Connection API does less things automatically than the Client
// API does. For instance, right here, we always assume set_proxy, so
// that if an absolute-form URI is provided, it is serialized as-is.
Expand All @@ -191,6 +192,7 @@ where
// It's important that this method isn't called directly from the
// `Client`, so that `set_proxy` there is still respected.
req.set_proxy(true);
*/
let inner = self.send_request_retryable(req).map_err(|e| {
let (err, _orig_req) = e;
err
Expand Down Expand Up @@ -485,3 +487,4 @@ impl AssertSendSync for Builder {}
// thing.
//#[doc(hidden)]
//impl AssertSend for ResponseFuture {}

6 changes: 4 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use header::{Host};
use proto;
use proto::request;
use method::Method;
use self::pool::Pool;
use self::pool::{Pool, Pooled};
use uri::{self, Uri};
use version::HttpVersion;

Expand Down Expand Up @@ -101,6 +101,7 @@ impl<C, B> Client<C, B> {
connector: Rc::new(config.connector),
executor: exec,
h1_writev: config.h1_writev,
keep_alive: config.keep_alive,
pool: Pool::new(config.keep_alive, config.keep_alive_timeout),
retry_canceled_requests: config.retry_canceled_requests,
set_host: config.set_host,
Expand Down Expand Up @@ -200,6 +201,7 @@ where C: Connect,
let pool = self.pool.clone();
let pool_key = Arc::new(domain.to_string());
let h1_writev = self.h1_writev;
let keep_alive = self.keep_alive;
let connector = self.connector.clone();
future::lazy(move || {
connector.connect(url)
Expand Down Expand Up @@ -228,7 +230,6 @@ where C: Connect,
ClientError::Normal(e)
});


let executor = self.executor.clone();
let resp = race.and_then(move |mut pooled| {
let conn_reused = pooled.is_reused();
Expand Down Expand Up @@ -292,6 +293,7 @@ impl<C, B> Clone for Client<C, B> {
connector: self.connector.clone(),
executor: self.executor.clone(),
h1_writev: self.h1_writev,
keep_alive: self.keep_alive,
pool: self.pool.clone(),
retry_canceled_requests: self.retry_canceled_requests,
set_host: self.set_host,
Expand Down
2 changes: 2 additions & 0 deletions src/proto/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ impl<B> Response<B> {
/// Read the body.
#[inline]
pub fn body_ref(&self) -> Option<&B> { self.body.as_ref() }

pub(crate) fn body_mut(&mut self) -> &mut Option<B> { &mut self.body }
}

impl Response<Body> {
Expand Down
4 changes: 3 additions & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ mod dispatch_impl {
let (closes_tx, closes) = mpsc::channel(10);

let (tx1, rx1) = oneshot::channel();
let (_tx2, rx2) = oneshot::channel::<()>();

thread::spawn(move || {
let mut sock = server.accept().unwrap().0;
Expand All @@ -1019,6 +1020,7 @@ mod dispatch_impl {
sock.read(&mut buf).expect("read 1");
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap();
let _ = tx1.send(());
let _ = rx2.wait();
});

let uri = format!("http://{}/a", addr).parse().unwrap();
Expand Down Expand Up @@ -1394,7 +1396,6 @@ mod conn {
core.run(res.join(rx).map(|r| r.0)).unwrap();
}


#[test]
fn pipeline() {
let server = TcpListener::bind("127.0.0.1:0").unwrap();
Expand All @@ -1411,6 +1412,7 @@ mod conn {
let mut buf = [0; 4096];
sock.read(&mut buf).expect("read 1");
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").unwrap();

let _ = tx1.send(());
});

Expand Down

0 comments on commit 192ce09

Please sign in to comment.