From f2f17982159c4d588972783e4f2ae592d363d747 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 19 Feb 2018 13:41:21 -0800 Subject: [PATCH] allow to send request using custom connector --- CHANGES.md | 4 ++++ src/client/pipeline.rs | 12 +++++++++--- src/client/request.rs | 7 +++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d688c4e93..b623c163f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,10 +14,14 @@ * Added StaticFiles::index_file() +* Added http client + * Added basic websocket client * Added TestServer::ws(), test websockets client +* Added TestServer test http client + * Allow to override content encoding on application level diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index 2cb3d635d..273a679ac 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -43,14 +43,21 @@ enum State { pub struct SendRequest { req: ClientRequest, state: State, + conn: Addr, } impl SendRequest { pub(crate) fn new(req: ClientRequest) -> SendRequest { + SendRequest::with_connector(req, ClientConnector::from_registry()) + } + + pub(crate) fn with_connector(req: ClientRequest, conn: Addr) + -> SendRequest + { SendRequest{ req: req, state: State::New, - } + conn: conn} } } @@ -64,8 +71,7 @@ impl Future for SendRequest { match state { State::New => - self.state = State::Connect( - ClientConnector::from_registry().send(Connect(self.req.uri().clone()))), + self.state = State::Connect(self.conn.send(Connect(self.req.uri().clone()))), State::Connect(mut conn) => match conn.poll() { Ok(Async::NotReady) => { self.state = State::Connect(conn); diff --git a/src/client/request.rs b/src/client/request.rs index c5aa487a5..f10cdfc17 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -1,6 +1,7 @@ use std::{fmt, mem}; use std::io::Write; +use actix::{Addr, Unsync}; use cookie::{Cookie, CookieJar}; use bytes::{BytesMut, BufMut}; use http::{HeaderMap, Method, Version, Uri, HttpTryFrom, Error as HttpError}; @@ -12,6 +13,7 @@ use body::Body; use error::Error; use headers::ContentEncoding; use super::pipeline::SendRequest; +use super::connector::ClientConnector; /// An HTTP Client Request pub struct ClientRequest { @@ -176,6 +178,11 @@ impl ClientRequest { pub fn send(self) -> SendRequest { SendRequest::new(self) } + + pub fn with_connector(self, conn: Addr) -> SendRequest { + SendRequest::with_connector(self, conn) + + } } impl fmt::Debug for ClientRequest {