From 9037473e0fc60b668cfb2b68beeed43d1a8891a0 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 25 Mar 2019 21:52:45 -0700 Subject: [PATCH] update client error --- Cargo.toml | 2 +- src/body.rs | 10 ++++++++++ src/client/connection.rs | 2 +- src/client/error.rs | 4 ++++ src/client/request.rs | 11 ++++++++--- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 84b974be5..da11a5853 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ failure = { version = "0.1.5", optional = true } openssl = { version="0.10", optional = true } [dev-dependencies] -actix-rt = "0.2.0" +actix-rt = "0.2.1" actix-server = { version = "0.4.0", features=["ssl"] } actix-connect = { version = "0.1.0", features=["ssl"] } actix-http-test = { path="test-server", features=["ssl"] } diff --git a/src/body.rs b/src/body.rs index b7e8ec98a..e1399e6b4 100644 --- a/src/body.rs +++ b/src/body.rs @@ -45,6 +45,16 @@ impl MessageBody for () { } } +impl MessageBody for Box { + fn length(&self) -> BodyLength { + self.as_ref().length() + } + + fn poll_next(&mut self) -> Poll, Error> { + self.as_mut().poll_next() + } +} + pub enum ResponseBody { Body(B), Other(Body), diff --git a/src/client/connection.rs b/src/client/connection.rs index 683738e28..8de23bd24 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -21,7 +21,7 @@ pub(crate) enum ConnectionType { pub trait Connection { type Future: Future; - /// Close connection + /// Send request and body fn send_request( self, head: RequestHead, diff --git a/src/client/error.rs b/src/client/error.rs index 4fce904f1..69ec49585 100644 --- a/src/client/error.rs +++ b/src/client/error.rs @@ -7,6 +7,7 @@ use trust_dns_resolver::error::ResolveError; use openssl::ssl::{Error as SslError, HandshakeError}; use crate::error::{Error, ParseError, ResponseError}; +use crate::http::Error as HttpError; use crate::response::Response; /// A set of errors that can occur while connecting to an HTTP host @@ -98,6 +99,9 @@ pub enum SendRequestError { Send(io::Error), /// Error parsing response Response(ParseError), + /// Http error + #[display(fmt = "{}", _0)] + Http(HttpError), /// Http2 error #[display(fmt = "{}", _0)] H2(h2::Error), diff --git a/src/client/request.rs b/src/client/request.rs index 26713aa46..134a42640 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -118,6 +118,11 @@ impl ClientRequest where B: MessageBody, { + /// Create new client request + pub fn new(head: RequestHead, body: B) -> Self { + ClientRequest { head, body } + } + /// Get the request URI #[inline] pub fn uri(&self) -> &Uri { @@ -174,14 +179,14 @@ where // Send request /// /// This method returns a future that resolves to a ClientResponse - pub fn send( + pub fn send( self, connector: &mut T, ) -> impl Future where B: 'static, - T: Service, - I: Connection, + T: Service, + T::Response: Connection, { let Self { head, body } = self;