Allow saving multiple idle streams per host. (#133)
Adds set_max_idle_connections and set_max_idle_connections_per_host. This turns the values of Pool.recycle into a VecDeque of Streams for the same PoolKey. The freshest stream (most recently used) is at the back; the stalest stream is at the front. This also removes the invariant "Each PoolKey exists in recycle at most once and lru at most once," replacing it with "each PoolKey has the same number of entries in lru as in recycle." Fixes #110
This commit is contained in:
32
src/agent.rs
32
src/agent.rs
@@ -166,6 +166,38 @@ impl Agent {
|
||||
Request::new(&self, method.into(), path.into())
|
||||
}
|
||||
|
||||
/// Sets the maximum number of connections allowed in the connection pool.
|
||||
/// By default, this is set to 100. Setting this to zero would disable
|
||||
/// connection pooling.
|
||||
///
|
||||
/// ```
|
||||
/// let agent = ureq::agent();
|
||||
/// agent.set_max_pool_connections(200);
|
||||
/// ```
|
||||
pub fn set_max_pool_connections(&self, max_connections: usize) {
|
||||
let mut optional_state = self.state.lock().unwrap();
|
||||
if let Some(state) = optional_state.as_mut() {
|
||||
state.pool.set_max_idle_connections(max_connections);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the maximum number of connections per host to keep in the
|
||||
/// connection pool. By default, this is set to 1. Setting this to zero
|
||||
/// would disable connection pooling.
|
||||
///
|
||||
/// ```
|
||||
/// let agent = ureq::agent();
|
||||
/// agent.set_max_pool_connections_per_host(10);
|
||||
/// ```
|
||||
pub fn set_max_pool_connections_per_host(&self, max_connections: usize) {
|
||||
let mut optional_state = self.state.lock().unwrap();
|
||||
if let Some(state) = optional_state.as_mut() {
|
||||
state
|
||||
.pool
|
||||
.set_max_idle_connections_per_host(max_connections);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a cookie in this agent by name. Cookies are available
|
||||
/// either by setting it in the agent, or by making requests
|
||||
/// that `Set-Cookie` in the agent.
|
||||
|
||||
Reference in New Issue
Block a user