Skip to content

Commit 454a720

Browse files
authored
Add Max Age CURL Option (#360)
* add max age option to CURL system crate * correctly identify constant and expose Rust API * correct API
1 parent badb448 commit 454a720

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

curl-sys/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ pub const CURLOPT_PROXY_CAPATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 247;
582582
pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254;
583583
pub const CURLOPT_PROXY_SSLKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 256;
584584

585+
pub const CURLOPT_MAXAGE_CONN: CURLoption = CURLOPTTYPE_LONG + 288;
586+
585587
pub const CURL_IPRESOLVE_WHATEVER: c_int = 0;
586588
pub const CURL_IPRESOLVE_V4: c_int = 1;
587589
pub const CURL_IPRESOLVE_V6: c_int = 2;

src/easy/handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,11 @@ impl Easy {
905905
self.inner.max_connects(max)
906906
}
907907

908+
/// Same as [`Easy2::maxage_conn`](struct.Easy2.html#method.maxage_conn)
909+
pub fn maxage_conn(&mut self, max_age: Duration) -> Result<(), Error> {
910+
self.inner.maxage_conn(max_age)
911+
}
912+
908913
/// Same as [`Easy2::fresh_connect`](struct.Easy2.html#method.fresh_connect)
909914
pub fn fresh_connect(&mut self, enable: bool) -> Result<(), Error> {
910915
self.inner.fresh_connect(enable)

src/easy/handler.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,17 @@ impl<H> Easy2<H> {
17411741
self.setopt_long(curl_sys::CURLOPT_MAXCONNECTS, max as c_long)
17421742
}
17431743

1744+
/// Set the maximum idle time allowed for a connection.
1745+
///
1746+
/// This configuration sets the maximum time that a connection inside of the connection cache
1747+
/// can be reused. Any connection older than this value will be considered stale and will
1748+
/// be closed.
1749+
///
1750+
/// By default, a value of 118 seconds is used.
1751+
pub fn maxage_conn(&mut self, max_age: Duration) -> Result<(), Error> {
1752+
self.setopt_long(curl_sys::CURLOPT_MAXAGE_CONN, max_age.as_secs() as c_long)
1753+
}
1754+
17441755
/// Force a new connection to be used.
17451756
///
17461757
/// Makes the next transfer use a new (fresh) connection by force instead of

systest/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn main() {
7979
if version < 66 {
8080
match s {
8181
"CURL_HTTP_VERSION_3" => return true,
82+
"CURLOPT_MAXAGE_CONN" => return true,
8283
_ => {}
8384
}
8485
}

0 commit comments

Comments
 (0)