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:
@@ -36,13 +36,13 @@ pub use net::{Fresh, Streaming};
|
||||
use HttpError::HttpIoError;
|
||||
use {HttpResult};
|
||||
use buffer::BufReader;
|
||||
use header::{Headers, Connection, Expect};
|
||||
use header::ConnectionOption::{Close, KeepAlive};
|
||||
use header::{Headers, Expect};
|
||||
use http;
|
||||
use method::Method;
|
||||
use net::{NetworkListener, NetworkStream, HttpListener};
|
||||
use status::StatusCode;
|
||||
use uri::RequestUri;
|
||||
use version::HttpVersion::{Http10, Http11};
|
||||
use version::HttpVersion::Http11;
|
||||
|
||||
use self::listener::ListenerPool;
|
||||
|
||||
@@ -206,11 +206,7 @@ where S: NetworkStream + Clone, H: Handler {
|
||||
}
|
||||
}
|
||||
|
||||
keep_alive = match (req.version, req.headers.get::<Connection>()) {
|
||||
(Http10, Some(conn)) if !conn.contains(&KeepAlive) => false,
|
||||
(Http11, Some(conn)) if conn.contains(&Close) => false,
|
||||
_ => true
|
||||
};
|
||||
keep_alive = http::should_keep_alive(req.version, &req.headers);
|
||||
let mut res = Response::new(&mut wrt);
|
||||
res.version = req.version;
|
||||
handler.handle(req, res);
|
||||
|
||||
Reference in New Issue
Block a user