diff --git a/curl-sys/lib.rs b/curl-sys/lib.rs index 9f70613687..28edab1cb5 100644 --- a/curl-sys/lib.rs +++ b/curl-sys/lib.rs @@ -582,6 +582,8 @@ pub const CURLOPT_PROXY_CAPATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 247; pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254; pub const CURLOPT_PROXY_SSLKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 256; +pub const CURLOPT_MAXAGE_CONN: CURLoption = CURLOPTTYPE_LONG + 288; + pub const CURL_IPRESOLVE_WHATEVER: c_int = 0; pub const CURL_IPRESOLVE_V4: c_int = 1; pub const CURL_IPRESOLVE_V6: c_int = 2; diff --git a/src/easy/handle.rs b/src/easy/handle.rs index fca2d3f602..b59430ebbb 100644 --- a/src/easy/handle.rs +++ b/src/easy/handle.rs @@ -905,6 +905,11 @@ impl Easy { self.inner.max_connects(max) } + /// Same as [`Easy2::maxage_conn`](struct.Easy2.html#method.maxage_conn) + pub fn maxage_conn(&mut self, max_age: Duration) -> Result<(), Error> { + self.inner.maxage_conn(max_age) + } + /// Same as [`Easy2::fresh_connect`](struct.Easy2.html#method.fresh_connect) pub fn fresh_connect(&mut self, enable: bool) -> Result<(), Error> { self.inner.fresh_connect(enable) diff --git a/src/easy/handler.rs b/src/easy/handler.rs index e505809f8b..fc0ea77c82 100644 --- a/src/easy/handler.rs +++ b/src/easy/handler.rs @@ -1741,6 +1741,17 @@ impl Easy2 { self.setopt_long(curl_sys::CURLOPT_MAXCONNECTS, max as c_long) } + /// Set the maximum idle time allowed for a connection. + /// + /// This configuration sets the maximum time that a connection inside of the connection cache + /// can be reused. Any connection older than this value will be considered stale and will + /// be closed. + /// + /// By default, a value of 118 seconds is used. + pub fn maxage_conn(&mut self, max_age: Duration) -> Result<(), Error> { + self.setopt_long(curl_sys::CURLOPT_MAXAGE_CONN, max_age.as_secs() as c_long) + } + /// Force a new connection to be used. /// /// Makes the next transfer use a new (fresh) connection by force instead of diff --git a/systest/build.rs b/systest/build.rs index 29b2f6c583..8965c89083 100644 --- a/systest/build.rs +++ b/systest/build.rs @@ -79,6 +79,7 @@ fn main() { if version < 66 { match s { "CURL_HTTP_VERSION_3" => return true, + "CURLOPT_MAXAGE_CONN" => return true, _ => {} } }