fix building without tls. close #1
This commit is contained in:
18
src/error.rs
18
src/error.rs
@@ -1,7 +1,11 @@
|
||||
use native_tls::Error as TlsError;
|
||||
use native_tls::HandshakeError;
|
||||
use std::io::Error as IoError;
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
use std::net::TcpStream;
|
||||
#[cfg(feature = "tls")]
|
||||
use native_tls::Error as TlsError;
|
||||
#[cfg(feature = "tls")]
|
||||
use native_tls::HandshakeError;
|
||||
|
||||
/// Errors that are translated to ["synthetic" responses](struct.Response.html#method.synthetic).
|
||||
#[derive(Debug)]
|
||||
@@ -23,8 +27,10 @@ pub enum Error {
|
||||
/// Some unspecified `std::io::Error`. Synthetic error `500`.
|
||||
Io(IoError),
|
||||
/// Some unspecified TLS error. Synthetic error `400`.
|
||||
#[cfg(feature = "tls")]
|
||||
Tls(TlsError),
|
||||
/// Some unspecified TLS handshake error. Synthetic error `500`.
|
||||
#[cfg(feature = "tls")]
|
||||
TlsHandshake(HandshakeError<TcpStream>),
|
||||
}
|
||||
|
||||
@@ -40,7 +46,9 @@ impl Error {
|
||||
Error::BadStatus => 500,
|
||||
Error::BadHeader => 500,
|
||||
Error::Io(_) => 500,
|
||||
#[cfg(feature = "tls")]
|
||||
Error::Tls(_) => 400,
|
||||
#[cfg(feature = "tls")]
|
||||
Error::TlsHandshake(_) => 500,
|
||||
}
|
||||
}
|
||||
@@ -56,7 +64,9 @@ impl Error {
|
||||
Error::BadStatus => "Bad Status",
|
||||
Error::BadHeader => "Bad Header",
|
||||
Error::Io(_) => "Network Error",
|
||||
#[cfg(feature = "tls")]
|
||||
Error::Tls(_) => "TLS Error",
|
||||
#[cfg(feature = "tls")]
|
||||
Error::TlsHandshake(_) => "TLS Handshake Error",
|
||||
}
|
||||
}
|
||||
@@ -72,7 +82,9 @@ impl Error {
|
||||
Error::BadStatus => "Bad Status".to_string(),
|
||||
Error::BadHeader => "Bad Header".to_string(),
|
||||
Error::Io(ioe) => format!("Network Error: {}", ioe),
|
||||
#[cfg(feature = "tls")]
|
||||
Error::Tls(tls) => format!("TLS Error: {}", tls),
|
||||
#[cfg(feature = "tls")]
|
||||
Error::TlsHandshake(he) => format!("TLS Handshake Error: {}", he),
|
||||
}
|
||||
}
|
||||
@@ -84,12 +96,14 @@ impl From<IoError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
impl From<TlsError> for Error {
|
||||
fn from(err: TlsError) -> Error {
|
||||
Error::Tls(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
impl From<HandshakeError<TcpStream>> for Error {
|
||||
fn from(err: HandshakeError<TcpStream>) -> Error {
|
||||
Error::TlsHandshake(err)
|
||||
|
||||
@@ -25,6 +25,7 @@ impl ::std::fmt::Debug for Stream {
|
||||
"Stream[{}]",
|
||||
match self {
|
||||
Stream::Http(_) => "http",
|
||||
#[cfg(feature = "tls")]
|
||||
Stream::Https(_) => "https",
|
||||
Stream::Cursor(_) => "cursor",
|
||||
#[cfg(test)]
|
||||
@@ -38,6 +39,7 @@ impl Stream {
|
||||
pub fn is_poolable(&self) -> bool {
|
||||
match self {
|
||||
Stream::Http(_) => true,
|
||||
#[cfg(feature = "tls")]
|
||||
Stream::Https(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@@ -56,6 +58,7 @@ impl Read for Stream {
|
||||
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.read(buf),
|
||||
#[cfg(feature = "tls")]
|
||||
Stream::Https(stream) => stream.read(buf),
|
||||
Stream::Cursor(read) => read.read(buf),
|
||||
#[cfg(test)]
|
||||
@@ -68,6 +71,7 @@ impl Write for Stream {
|
||||
fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.write(buf),
|
||||
#[cfg(feature = "tls")]
|
||||
Stream::Https(stream) => stream.write(buf),
|
||||
Stream::Cursor(_) => panic!("Write to read only stream"),
|
||||
#[cfg(test)]
|
||||
@@ -77,6 +81,7 @@ impl Write for Stream {
|
||||
fn flush(&mut self) -> IoResult<()> {
|
||||
match self {
|
||||
Stream::Http(sock) => sock.flush(),
|
||||
#[cfg(feature = "tls")]
|
||||
Stream::Https(stream) => stream.flush(),
|
||||
Stream::Cursor(_) => panic!("Flush read only stream"),
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user