Skip to content

Commit

Permalink
Add new CURLINFO_ constants and fn response_http_version()
Browse files Browse the repository at this point in the history
Use `CURLINFO_HTTP_VERSION` (a new constant for the `curl-sys` crate) to
determine the HTTP version used in the last/latest connection.
  • Loading branch information
MarijnS95 committed Nov 26, 2023
1 parent de57280 commit 4eef5a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ pub const CURLINFO_STRING: CURLINFO = 0x100000;
pub const CURLINFO_LONG: CURLINFO = 0x200000;
pub const CURLINFO_DOUBLE: CURLINFO = 0x300000;
pub const CURLINFO_SLIST: CURLINFO = 0x400000;
pub const CURLINFO_PTR: CURLINFO = 0x400000; /* same as SLIST */
pub const CURLINFO_SOCKET: CURLINFO = 0x500000;
pub const CURLINFO_OFF_T: CURLINFO = 0x600000;
pub const CURLINFO_MASK: CURLINFO = 0x0fffff;
pub const CURLINFO_TYPEMASK: CURLINFO = 0xf00000;

Expand Down Expand Up @@ -809,6 +812,27 @@ pub const CURLINFO_PRIMARY_PORT: CURLINFO = CURLINFO_LONG + 40;
pub const CURLINFO_LOCAL_IP: CURLINFO = CURLINFO_STRING + 41;
pub const CURLINFO_LOCAL_PORT: CURLINFO = CURLINFO_LONG + 42;
// pub const CURLINFO_TLS_SESSION: CURLINFO = CURLINFO_SLIST + 43;
pub const CURLINFO_ACTIVESOCKET: CURLINFO = CURLINFO_SOCKET + 44;
pub const CURLINFO_TLS_SSL_PTR: CURLINFO = CURLINFO_PTR + 45;
pub const CURLINFO_HTTP_VERSION: CURLINFO = CURLINFO_LONG + 46;
pub const CURLINFO_PROXY_SSL_VERIFYRESULT: CURLINFO = CURLINFO_LONG + 47;
pub const CURLINFO_PROTOCOL: CURLINFO = CURLINFO_LONG + 48;
pub const CURLINFO_SCHEME: CURLINFO = CURLINFO_STRING + 49;
pub const CURLINFO_TOTAL_TIME_T: CURLINFO = CURLINFO_OFF_T + 50;
pub const CURLINFO_NAMELOOKUP_TIME_T: CURLINFO = CURLINFO_OFF_T + 51;
pub const CURLINFO_CONNECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 52;
pub const CURLINFO_PRETRANSFER_TIME_T: CURLINFO = CURLINFO_OFF_T + 53;
pub const CURLINFO_STARTTRANSFER_TIME_T: CURLINFO = CURLINFO_OFF_T + 54;
pub const CURLINFO_REDIRECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 55;
pub const CURLINFO_APPCONNECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 56;
pub const CURLINFO_RETRY_AFTER: CURLINFO = CURLINFO_OFF_T + 57;
pub const CURLINFO_EFFECTIVE_METHOD: CURLINFO = CURLINFO_STRING + 58;
pub const CURLINFO_PROXY_ERROR: CURLINFO = CURLINFO_LONG + 59;
pub const CURLINFO_REFERER: CURLINFO = CURLINFO_STRING + 60;
pub const CURLINFO_CAINFO: CURLINFO = CURLINFO_STRING + 61;
pub const CURLINFO_CAPATH: CURLINFO = CURLINFO_STRING + 62;
pub const CURLINFO_XFER_ID: CURLINFO = CURLINFO_OFF_T + 63;
pub const CURLINFO_CONN_ID: CURLINFO = CURLINFO_OFF_T + 64;

pub type curl_closepolicy = __enum_ty;
pub const CURLCLOSEPOLICY_NONE: curl_closepolicy = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,20 @@ impl<H> Easy2<H> {
Ok(list::from_raw(list))
}
}
/// Get the last http version number
///
/// Corresponds to `CURLINFO_HTTP_VERSION` and may return an error if the
/// option isn't supported.
pub fn response_http_version(&self) -> Result<HttpVersion, Error> {
self.getopt_long(curl_sys::CURLINFO_HTTP_VERSION)
.map(|c| match c as i32 {
curl_sys::CURL_HTTP_VERSION_1_0 => HttpVersion::V10,
curl_sys::CURL_HTTP_VERSION_1_1 => HttpVersion::V11,
curl_sys::CURL_HTTP_VERSION_2_0 => HttpVersion::V2,
curl_sys::CURL_HTTP_VERSION_3 => HttpVersion::V3,
_ => unreachable!("TODO"),
})
}

/// Wait for pipelining/multiplexing
///
Expand Down

0 comments on commit 4eef5a5

Please sign in to comment.