1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-26 19:41:12 +00:00

allow to send request using custom connector

This commit is contained in:
Nikolay Kim 2018-02-19 13:41:21 -08:00
parent 548f4e4d62
commit f2f1798215
3 changed files with 20 additions and 3 deletions

View file

@ -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

View file

@ -43,14 +43,21 @@ enum State {
pub struct SendRequest {
req: ClientRequest,
state: State,
conn: Addr<Unsync, ClientConnector>,
}
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<Unsync, ClientConnector>)
-> 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);

View file

@ -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<Unsync, ClientConnector>) -> SendRequest {
SendRequest::with_connector(self, conn)
}
}
impl fmt::Debug for ClientRequest {