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:
12
src/http.rs
12
src/http.rs
@@ -7,7 +7,8 @@ use std::fmt;
|
||||
use httparse;
|
||||
|
||||
use buffer::BufReader;
|
||||
use header::Headers;
|
||||
use header::{Headers, Connection};
|
||||
use header::ConnectionOption::{Close, KeepAlive};
|
||||
use method::Method;
|
||||
use status::StatusCode;
|
||||
use uri::RequestUri;
|
||||
@@ -443,6 +444,15 @@ pub const LINE_ENDING: &'static str = "\r\n";
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct RawStatus(pub u16, pub Cow<'static, str>);
|
||||
|
||||
/// Checks if a connection should be kept alive.
|
||||
pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool {
|
||||
match (version, headers.get::<Connection>()) {
|
||||
(Http10, Some(conn)) if !conn.contains(&KeepAlive) => false,
|
||||
(Http11, Some(conn)) if conn.contains(&Close) => false,
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::{self, Write};
|
||||
|
||||
Reference in New Issue
Block a user