diff --git a/src/agent.rs b/src/agent.rs index b33c8f8..9eed56e 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -50,7 +50,7 @@ pub struct Agent { /// /// *Internal API*. #[derive(Debug)] -pub struct AgentState { +pub(crate) struct AgentState { /// Reused connections between requests. pool: ConnectionPool, /// Cookies saved between requests. @@ -250,7 +250,7 @@ impl Agent { } #[cfg(test)] - pub fn state(&self) -> &Arc>> { + pub(crate) fn state(&self) -> &Arc>> { &self.state } } diff --git a/src/body.rs b/src/body.rs index 5795e8c..50985f7 100644 --- a/src/body.rs +++ b/src/body.rs @@ -17,7 +17,7 @@ use serde_json; /// The different kinds of bodies to send. /// /// *Internal API* -pub enum Payload { +pub(crate) enum Payload { Empty, Text(String, String), #[cfg(feature = "json")] @@ -48,7 +48,7 @@ impl Default for Payload { /// Payloads are turned into this type where we can hold both a size and the reader. /// /// *Internal API* -pub struct SizedReader { +pub(crate) struct SizedReader { pub size: Option, pub reader: Box, } @@ -96,7 +96,11 @@ impl Payload { } /// Helper to send a body, either as chunked or not. -pub fn send_body(mut body: SizedReader, do_chunk: bool, stream: &mut Stream) -> IoResult<()> { +pub(crate) fn send_body( + mut body: SizedReader, + do_chunk: bool, + stream: &mut Stream, +) -> IoResult<()> { if do_chunk { let mut chunker = chunked_transfer::Encoder::new(stream); copy(&mut body.reader, &mut chunker)?; diff --git a/src/pool.rs b/src/pool.rs index 18e50f6..335db3e 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -10,7 +10,7 @@ pub const DEFAULT_HOST: &str = "localhost"; /// /// *Internal API* #[derive(Default, Debug)] -pub struct ConnectionPool { +pub(crate) struct ConnectionPool { // the actual pooled connection. however only one per hostname:port. recycle: HashMap, } @@ -61,7 +61,7 @@ impl PoolKey { /// read is exhausted (reached a 0). /// /// *Internal API* -pub struct PoolReturnRead { +pub(crate) struct PoolReturnRead { // unit that contains the agent where we want to return the reader. unit: Option, // pointer to underlying stream diff --git a/src/response.rs b/src/response.rs index 85acd4c..5df9a6f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -526,7 +526,7 @@ fn read_next_line(reader: &mut R) -> IoResult { /// Read Wrapper around an (unsafe) pointer to a Stream. /// /// *Internal API* -struct YoloRead { +pub(crate) struct YoloRead { stream: *mut Stream, dealloc: bool, // whether we are to dealloc stream on drop } @@ -560,8 +560,6 @@ impl Drop for YoloRead { } /// Limits a YoloRead to a content size (as set by a "Content-Length" header). -/// -/// *Internal API* struct LimitedRead { reader: YoloRead, limit: usize, @@ -604,7 +602,7 @@ impl Read for LimitedRead { /// "Content-Type: text/plain; charset=iso8859-1" -> "iso8859-1" /// /// *Internal API* -pub fn charset_from_content_type(header: Option<&str>) -> &str { +pub(crate) fn charset_from_content_type(header: Option<&str>) -> &str { header .and_then(|header| { header.find(';').and_then(|semi| { diff --git a/src/stream.rs b/src/stream.rs index c1091bd..48d9432 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -89,7 +89,7 @@ impl Write for Stream { } } -pub fn connect_http(unit: &Unit) -> Result { +pub(crate) fn connect_http(unit: &Unit) -> Result { // let hostname = unit.url.host_str().unwrap(); let port = unit.url.port().unwrap_or(80); @@ -98,7 +98,7 @@ pub fn connect_http(unit: &Unit) -> Result { } #[cfg(feature = "tls")] -pub fn connect_https(unit: &Unit) -> Result { +pub(crate) fn connect_https(unit: &Unit) -> Result { use std::sync::Arc; lazy_static! { @@ -124,7 +124,7 @@ pub fn connect_https(unit: &Unit) -> Result { Ok(Stream::Https(stream)) } -pub fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result { +pub(crate) fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result { // let ips: Vec = format!("{}:{}", hostname, port) .to_socket_addrs() @@ -164,13 +164,13 @@ pub fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result Result { +pub(crate) fn connect_test(unit: &Unit) -> Result { use crate::test; test::resolve_handler(unit) } #[cfg(not(test))] -pub fn connect_test(unit: &Unit) -> Result { +pub(crate) fn connect_test(unit: &Unit) -> Result { Err(Error::UnknownScheme(unit.url.scheme().to_string())) } diff --git a/src/test/mod.rs b/src/test/mod.rs index 9984362..b1824db 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -18,11 +18,11 @@ mod simple; type RequestHandler = Fn(&Unit) -> Result + Send + 'static; lazy_static! { - pub static ref TEST_HANDLERS: Arc>>> = + pub(crate) static ref TEST_HANDLERS: Arc>>> = { Arc::new(Mutex::new(HashMap::new())) }; } -pub fn set_handler(path: &str, handler: H) +pub(crate) fn set_handler(path: &str, handler: H) where H: Fn(&Unit) -> Result + Send + 'static, { @@ -48,7 +48,7 @@ pub fn make_response( Ok(Stream::Test(Box::new(cursor), write)) } -pub fn resolve_handler(unit: &Unit) -> Result { +pub(crate) fn resolve_handler(unit: &Unit) -> Result { let mut handlers = TEST_HANDLERS.lock().unwrap(); let path = unit.url.path(); let handler = handlers.remove(path).unwrap(); diff --git a/src/unit.rs b/src/unit.rs index c0e25eb..3278450 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -11,7 +11,7 @@ use crate::pool::DEFAULT_HOST; /// /// *Internal API* #[derive(Debug)] -pub struct Unit { +pub(crate) struct Unit { pub agent: Arc>>, pub url: Url, pub is_chunked: bool, @@ -109,7 +109,7 @@ impl Unit { } /// Perform a connection. Used recursively for redirects. -pub fn connect( +pub(crate) fn connect( req: &Request, unit: Unit, use_pooled: bool,