diff --git a/Cargo.toml b/Cargo.toml index 3805b53d..834e3211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ version = "0.6" optional = true [dependencies.solicit] -version = "0.3" +version = "0.4" default-features = false [dev-dependencies] diff --git a/src/http/h2.rs b/src/http/h2.rs index cb3a5fe8..7d6d9f68 100644 --- a/src/http/h2.rs +++ b/src/http/h2.rs @@ -24,7 +24,7 @@ use solicit::http::Header as Http2Header; use solicit::http::HttpScheme; use solicit::http::HttpError as Http2Error; use solicit::http::transport::TransportStream; -use solicit::http::client::{ClientStream, HttpConnect, write_preface}; +use solicit::http::client::{ClientStream, HttpConnect, HttpConnectError, write_preface}; use solicit::client::SimpleClient; use httparse; @@ -75,13 +75,38 @@ struct Http2Connector where S: CloneableStream { host: String, } +#[derive(Debug)] +struct Http2ConnectError(io::Error); + +impl ::std::fmt::Display for Http2ConnectError { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + write!(fmt, "HTTP/2 connect error: {}", (self as &::std::error::Error).description()) + } +} + +impl ::std::error::Error for Http2ConnectError { + fn description(&self) -> &str { + self.0.description() + } + + fn cause(&self) -> Option<&::std::error::Error> { + self.0.cause() + } +} + +impl HttpConnectError for Http2ConnectError {} + +impl From for Http2ConnectError { + fn from(e: io::Error) -> Http2ConnectError { Http2ConnectError(e) } +} + impl HttpConnect for Http2Connector where S: CloneableStream { /// The type of the underlying transport stream that the `HttpConnection`s /// produced by this `HttpConnect` implementation will be based on. type Stream = Http2Stream; /// The type of the error that can be produced by trying to establish the /// connection (i.e. calling the `connect` method). - type Err = ::Error; + type Err = Http2ConnectError; /// Establishes a network connection that can be used by HTTP/2 connections. fn connect(mut self) -> Result, Self::Err> {