2018-04-15 05:42:47 +00:00
|
|
|
use std::error::Error;
|
2018-04-12 04:14:16 +00:00
|
|
|
use std::io::{
|
2018-04-14 22:18:50 +00:00
|
|
|
Error as IoError,
|
2018-04-15 05:42:47 +00:00
|
|
|
ErrorKind,
|
2018-04-14 22:18:50 +00:00
|
|
|
stdin,
|
|
|
|
Stdin
|
2018-04-12 04:14:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
use futures::{
|
2018-04-14 22:18:50 +00:00
|
|
|
prelude::*,
|
|
|
|
stream::MapErr
|
|
|
|
};
|
2018-04-15 05:42:47 +00:00
|
|
|
use hyper::Error as HyperError;
|
2018-04-14 22:18:50 +00:00
|
|
|
use tokio_io::{
|
|
|
|
io::AllowStdIo,
|
|
|
|
codec::{
|
|
|
|
BytesCodec,
|
|
|
|
FramedRead
|
|
|
|
}
|
2018-04-12 04:14:16 +00:00
|
|
|
};
|
2018-04-14 07:34:59 +00:00
|
|
|
use webmetro::error::WebmetroError;
|
2018-04-12 04:14:16 +00:00
|
|
|
|
2018-04-12 01:54:02 +00:00
|
|
|
pub mod dump;
|
2018-04-12 06:03:46 +00:00
|
|
|
pub mod filter;
|
2018-04-11 05:39:28 +00:00
|
|
|
pub mod relay;
|
2018-04-12 04:14:16 +00:00
|
|
|
|
2018-04-14 22:18:50 +00:00
|
|
|
/// An adapter that makes chunks of bytes from stdin available as a Stream;
|
|
|
|
/// is NOT actually async, and just uses blocking read. Don't use more than
|
|
|
|
/// one at once, who knows who gets which bytes.
|
|
|
|
pub fn stdin_stream() -> MapErr<FramedRead<AllowStdIo<Stdin>, BytesCodec>, fn(IoError) -> WebmetroError> {
|
|
|
|
FramedRead::new(AllowStdIo::new(stdin()), BytesCodec::new())
|
|
|
|
.map_err(WebmetroError::IoError)
|
2018-04-12 04:14:16 +00:00
|
|
|
}
|
2018-04-15 05:42:47 +00:00
|
|
|
|
|
|
|
pub fn to_hyper_error(err: WebmetroError) -> HyperError {
|
|
|
|
match err {
|
|
|
|
WebmetroError::IoError(io_err) => io_err.into(),
|
|
|
|
err => IoError::new(ErrorKind::InvalidData, err.description()).into()
|
|
|
|
}
|
|
|
|
}
|