separate out ConnectionPool
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use cookie::{Cookie, CookieJar};
|
use cookie::{Cookie, CookieJar};
|
||||||
|
use conn::ConnectionPool;
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use response::{self, Response};
|
use response::{self, Response};
|
||||||
use std::sync::Mutex;
|
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
|
// to get to share private fields
|
||||||
include!("request.rs");
|
include!("request.rs");
|
||||||
include!("conn.rs");
|
|
||||||
include!("stream.rs");
|
include!("stream.rs");
|
||||||
include!("unit.rs");
|
include!("unit.rs");
|
||||||
|
|
||||||
|
|||||||
32
src/conn.rs
32
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)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct ConnectionPool {}
|
pub struct ConnectionPool {}
|
||||||
@@ -12,29 +8,3 @@ impl ConnectionPool {
|
|||||||
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<R, W>(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(())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ extern crate native_tls;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
mod agent;
|
mod agent;
|
||||||
|
mod conn;
|
||||||
mod error;
|
mod error;
|
||||||
mod header;
|
mod header;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|||||||
@@ -3,12 +3,17 @@ use std::net::TcpStream;
|
|||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::io::Result as IoResult;
|
use std::io::Result as IoResult;
|
||||||
|
use std::io::Write;
|
||||||
|
use url::Url;
|
||||||
|
use chunked_transfer;
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
use native_tls::TlsConnector;
|
use native_tls::TlsConnector;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
use native_tls::TlsStream;
|
use native_tls::TlsStream;
|
||||||
|
|
||||||
|
const CHUNK_SIZE: usize = 1024 * 1024;
|
||||||
|
|
||||||
pub enum Stream {
|
pub enum Stream {
|
||||||
Http(TcpStream),
|
Http(TcpStream),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
@@ -131,3 +136,29 @@ fn connect_test(unit: &Unit) -> Result<Stream, Error> {
|
|||||||
fn connect_https(unit: &Unit) -> Result<Stream, Error> {
|
fn connect_https(unit: &Unit) -> Result<Stream, Error> {
|
||||||
Err(Error::UnknownScheme(unit.url.scheme().to_string()))
|
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<R, W>(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(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user