diff --git a/src/agent.rs b/src/agent.rs index 8354dbe..b6a0037 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -1,4 +1,5 @@ use cookie::{Cookie, CookieJar}; +use conn::ConnectionPool; use error::Error; use response::{self, Response}; use std::sync::Mutex; @@ -7,7 +8,6 @@ use header::{add_header, get_all_headers, get_header, has_header, Header}; // to get to share private fields include!("request.rs"); -include!("conn.rs"); include!("stream.rs"); include!("unit.rs"); diff --git a/src/conn.rs b/src/conn.rs index d09ff7f..eb3b13f 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -1,8 +1,4 @@ -use std::io::Write; -use url::Url; -use chunked_transfer; - -const CHUNK_SIZE: usize = 1024 * 1024; +// #[derive(Debug, Default, Clone)] pub struct ConnectionPool {} @@ -12,29 +8,3 @@ impl ConnectionPool { ConnectionPool {} } } - -fn send_body(body: SizedReader, do_chunk: bool, stream: &mut Stream) -> IoResult<()> { - if do_chunk { - pipe(body.reader, chunked_transfer::Encoder::new(stream))?; - } else { - pipe(body.reader, stream)?; - } - - Ok(()) -} - -fn pipe(mut reader: R, mut writer: W) -> IoResult<()> -where - R: Read, - W: Write, -{ - let mut buf = [0_u8; CHUNK_SIZE]; - loop { - let len = reader.read(&mut buf)?; - if len == 0 { - break; - } - writer.write_all(&buf[0..len])?; - } - Ok(()) -} diff --git a/src/lib.rs b/src/lib.rs index 7d61c4e..d5912d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,6 +107,7 @@ extern crate native_tls; extern crate serde_json; mod agent; +mod conn; mod error; mod header; mod macros; diff --git a/src/stream.rs b/src/stream.rs index 2dff88f..9eb6cc7 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -3,12 +3,17 @@ use std::net::TcpStream; use std::net::ToSocketAddrs; use std::time::Duration; use std::io::Result as IoResult; +use std::io::Write; +use url::Url; +use chunked_transfer; #[cfg(feature = "tls")] use native_tls::TlsConnector; #[cfg(feature = "tls")] use native_tls::TlsStream; +const CHUNK_SIZE: usize = 1024 * 1024; + pub enum Stream { Http(TcpStream), #[cfg(feature = "tls")] @@ -131,3 +136,29 @@ fn connect_test(unit: &Unit) -> Result { fn connect_https(unit: &Unit) -> Result { Err(Error::UnknownScheme(unit.url.scheme().to_string())) } + +fn send_body(body: SizedReader, do_chunk: bool, stream: &mut Stream) -> IoResult<()> { + if do_chunk { + pipe(body.reader, chunked_transfer::Encoder::new(stream))?; + } else { + pipe(body.reader, stream)?; + } + + Ok(()) +} + +fn pipe(mut reader: R, mut writer: W) -> IoResult<()> +where + R: Read, + W: Write, +{ + let mut buf = [0_u8; CHUNK_SIZE]; + loop { + let len = reader.read(&mut buf)?; + if len == 0 { + break; + } + writer.write_all(&buf[0..len])?; + } + Ok(()) +}