mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-30 18:34:36 +01:00
update client error
This commit is contained in:
parent
c5c7b244be
commit
9037473e0f
@ -83,7 +83,7 @@ failure = { version = "0.1.5", optional = true }
|
|||||||
openssl = { version="0.10", optional = true }
|
openssl = { version="0.10", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "0.2.0"
|
actix-rt = "0.2.1"
|
||||||
actix-server = { version = "0.4.0", features=["ssl"] }
|
actix-server = { version = "0.4.0", features=["ssl"] }
|
||||||
actix-connect = { version = "0.1.0", features=["ssl"] }
|
actix-connect = { version = "0.1.0", features=["ssl"] }
|
||||||
actix-http-test = { path="test-server", features=["ssl"] }
|
actix-http-test = { path="test-server", features=["ssl"] }
|
||||||
|
10
src/body.rs
10
src/body.rs
@ -45,6 +45,16 @@ impl MessageBody for () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: MessageBody> MessageBody for Box<T> {
|
||||||
|
fn length(&self) -> BodyLength {
|
||||||
|
self.as_ref().length()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_next(&mut self) -> Poll<Option<Bytes>, Error> {
|
||||||
|
self.as_mut().poll_next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum ResponseBody<B> {
|
pub enum ResponseBody<B> {
|
||||||
Body(B),
|
Body(B),
|
||||||
Other(Body),
|
Other(Body),
|
||||||
|
@ -21,7 +21,7 @@ pub(crate) enum ConnectionType<Io> {
|
|||||||
pub trait Connection {
|
pub trait Connection {
|
||||||
type Future: Future<Item = ClientResponse, Error = SendRequestError>;
|
type Future: Future<Item = ClientResponse, Error = SendRequestError>;
|
||||||
|
|
||||||
/// Close connection
|
/// Send request and body
|
||||||
fn send_request<B: MessageBody + 'static>(
|
fn send_request<B: MessageBody + 'static>(
|
||||||
self,
|
self,
|
||||||
head: RequestHead,
|
head: RequestHead,
|
||||||
|
@ -7,6 +7,7 @@ use trust_dns_resolver::error::ResolveError;
|
|||||||
use openssl::ssl::{Error as SslError, HandshakeError};
|
use openssl::ssl::{Error as SslError, HandshakeError};
|
||||||
|
|
||||||
use crate::error::{Error, ParseError, ResponseError};
|
use crate::error::{Error, ParseError, ResponseError};
|
||||||
|
use crate::http::Error as HttpError;
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
|
|
||||||
/// A set of errors that can occur while connecting to an HTTP host
|
/// A set of errors that can occur while connecting to an HTTP host
|
||||||
@ -98,6 +99,9 @@ pub enum SendRequestError {
|
|||||||
Send(io::Error),
|
Send(io::Error),
|
||||||
/// Error parsing response
|
/// Error parsing response
|
||||||
Response(ParseError),
|
Response(ParseError),
|
||||||
|
/// Http error
|
||||||
|
#[display(fmt = "{}", _0)]
|
||||||
|
Http(HttpError),
|
||||||
/// Http2 error
|
/// Http2 error
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{}", _0)]
|
||||||
H2(h2::Error),
|
H2(h2::Error),
|
||||||
|
@ -118,6 +118,11 @@ impl<B> ClientRequest<B>
|
|||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
|
/// Create new client request
|
||||||
|
pub fn new(head: RequestHead, body: B) -> Self {
|
||||||
|
ClientRequest { head, body }
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the request URI
|
/// Get the request URI
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn uri(&self) -> &Uri {
|
pub fn uri(&self) -> &Uri {
|
||||||
@ -174,14 +179,14 @@ where
|
|||||||
// Send request
|
// Send request
|
||||||
///
|
///
|
||||||
/// This method returns a future that resolves to a ClientResponse
|
/// This method returns a future that resolves to a ClientResponse
|
||||||
pub fn send<T, I>(
|
pub fn send<T>(
|
||||||
self,
|
self,
|
||||||
connector: &mut T,
|
connector: &mut T,
|
||||||
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
||||||
where
|
where
|
||||||
B: 'static,
|
B: 'static,
|
||||||
T: Service<Request = Uri, Response = I, Error = ConnectError>,
|
T: Service<Request = Uri, Error = ConnectError>,
|
||||||
I: Connection,
|
T::Response: Connection,
|
||||||
{
|
{
|
||||||
let Self { head, body } = self;
|
let Self { head, body } = self;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user