Request::with_stream to use a different NetWorkStream in Client

added benches for mocking out the tcp process
This commit is contained in:
Sean McArthur
2014-09-11 08:26:03 -07:00
parent 4115c0e219
commit c40b5b0c53
2 changed files with 140 additions and 1 deletions

View File

@@ -38,6 +38,11 @@ impl<W: WriteStatus> Request<W> {
impl Request<Fresh> {
/// Create a new client request.
pub fn new(method: method::Method, url: Url) -> HttpResult<Request<Fresh>> {
Request::with_stream::<HttpStream>(method, url)
}
/// Create a new client request with a specific underlying NetworkStream.
pub fn with_stream<S: NetworkStream>(method: method::Method, url: Url) -> HttpResult<Request<Fresh>> {
debug!("{} {}", method, url);
let host = match url.serialize_host() {
Some(host) => host,
@@ -50,7 +55,7 @@ impl Request<Fresh> {
};
debug!("port={}", port);
let stream: HttpStream = try_io!(NetworkStream::connect(host.as_slice(), port));
let stream: S = try_io!(NetworkStream::connect(host.as_slice(), port));
let stream = BufferedWriter::new(stream.abstract());
let mut headers = Headers::new();
headers.set(Host(host));