pub(crate) where we can

This commit is contained in:
Martin Algesten
2018-12-20 11:08:20 +01:00
parent 1519dcb0b1
commit 07fd4d2cd5
7 changed files with 23 additions and 21 deletions

View File

@@ -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<Mutex<Option<AgentState>>> {
pub(crate) fn state(&self) -> &Arc<Mutex<Option<AgentState>>> {
&self.state
}
}

View File

@@ -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<usize>,
pub reader: Box<dyn Read + 'static>,
}
@@ -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)?;

View File

@@ -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<PoolKey, Stream>,
}
@@ -61,7 +61,7 @@ impl PoolKey {
/// read is exhausted (reached a 0).
///
/// *Internal API*
pub struct PoolReturnRead<R: Read + Sized> {
pub(crate) struct PoolReturnRead<R: Read + Sized> {
// unit that contains the agent where we want to return the reader.
unit: Option<Unit>,
// pointer to underlying stream

View File

@@ -526,7 +526,7 @@ fn read_next_line<R: Read>(reader: &mut R) -> IoResult<AsciiString> {
/// 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| {

View File

@@ -89,7 +89,7 @@ impl Write for Stream {
}
}
pub fn connect_http(unit: &Unit) -> Result<Stream, Error> {
pub(crate) fn connect_http(unit: &Unit) -> Result<Stream, Error> {
//
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<Stream, Error> {
}
#[cfg(feature = "tls")]
pub fn connect_https(unit: &Unit) -> Result<Stream, Error> {
pub(crate) fn connect_https(unit: &Unit) -> Result<Stream, Error> {
use std::sync::Arc;
lazy_static! {
@@ -124,7 +124,7 @@ pub fn connect_https(unit: &Unit) -> Result<Stream, Error> {
Ok(Stream::Https(stream))
}
pub fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result<TcpStream, Error> {
pub(crate) fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result<TcpStream, Error> {
//
let ips: Vec<SocketAddr> = format!("{}:{}", hostname, port)
.to_socket_addrs()
@@ -164,13 +164,13 @@ pub fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result<TcpStream,
}
#[cfg(test)]
pub fn connect_test(unit: &Unit) -> Result<Stream, Error> {
pub(crate) fn connect_test(unit: &Unit) -> Result<Stream, Error> {
use crate::test;
test::resolve_handler(unit)
}
#[cfg(not(test))]
pub fn connect_test(unit: &Unit) -> Result<Stream, Error> {
pub(crate) fn connect_test(unit: &Unit) -> Result<Stream, Error> {
Err(Error::UnknownScheme(unit.url.scheme().to_string()))
}

View File

@@ -18,11 +18,11 @@ mod simple;
type RequestHandler = Fn(&Unit) -> Result<Stream, Error> + Send + 'static;
lazy_static! {
pub static ref TEST_HANDLERS: Arc<Mutex<HashMap<String, Box<RequestHandler>>>> =
pub(crate) static ref TEST_HANDLERS: Arc<Mutex<HashMap<String, Box<RequestHandler>>>> =
{ Arc::new(Mutex::new(HashMap::new())) };
}
pub fn set_handler<H>(path: &str, handler: H)
pub(crate) fn set_handler<H>(path: &str, handler: H)
where
H: Fn(&Unit) -> Result<Stream, Error> + Send + 'static,
{
@@ -48,7 +48,7 @@ pub fn make_response(
Ok(Stream::Test(Box::new(cursor), write))
}
pub fn resolve_handler(unit: &Unit) -> Result<Stream, Error> {
pub(crate) fn resolve_handler(unit: &Unit) -> Result<Stream, Error> {
let mut handlers = TEST_HANDLERS.lock().unwrap();
let path = unit.url.path();
let handler = handlers.remove(path).unwrap();

View File

@@ -11,7 +11,7 @@ use crate::pool::DEFAULT_HOST;
///
/// *Internal API*
#[derive(Debug)]
pub struct Unit {
pub(crate) struct Unit {
pub agent: Arc<Mutex<Option<AgentState>>>,
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,