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