feat(client): add a Connection Pool
This adds a connection pool to the Client that is used by default. It accepts any other NetworkConnector, and simply acts as a NetworkConnector itself. Other Pools can exist by simply providing a custom NetworkConnector. This Pool is only used by default if you also use the default connector, which is `HttpConnector`. If you wish to use the Pool with a custom connector, you'll need to create the Pool with your custom connector, and then pass that pool to the Client::with_connector. This also adds a method to `NetworkStream`, `close`, which can be used to know when the Stream should be put down, because a server requested that the connection close instead of be kept alive. Closes #363 Closes #41
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| //! Client Requests | ||||
| use std::marker::PhantomData; | ||||
| use std::io::{self, Write, BufWriter}; | ||||
| use std::net::Shutdown; | ||||
|  | ||||
| use url::Url; | ||||
|  | ||||
| @@ -8,7 +9,7 @@ use method::{self, Method}; | ||||
| use header::Headers; | ||||
| use header::{self, Host}; | ||||
| use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming}; | ||||
| use http::{HttpWriter, LINE_ENDING}; | ||||
| use http::{self, HttpWriter, LINE_ENDING}; | ||||
| use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter, EmptyWriter}; | ||||
| use version; | ||||
| use HttpResult; | ||||
| @@ -154,7 +155,10 @@ impl Request<Streaming> { | ||||
|     /// | ||||
|     /// Consumes the Request. | ||||
|     pub fn send(self) -> HttpResult<Response> { | ||||
|         let raw = try!(self.body.end()).into_inner().unwrap(); // end() already flushes | ||||
|         let mut raw = try!(self.body.end()).into_inner().unwrap(); // end() already flushes | ||||
|         if !http::should_keep_alive(self.version, &self.headers) { | ||||
|             try!(raw.close(Shutdown::Write)); | ||||
|         } | ||||
|         Response::new(raw) | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user