Skip to content

Commit 4eef5a5

Browse files
committed
Add new CURLINFO_ constants and fn response_http_version()
Use `CURLINFO_HTTP_VERSION` (a new constant for the `curl-sys` crate) to determine the HTTP version used in the last/latest connection.
1 parent de57280 commit 4eef5a5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

curl-sys/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ pub const CURLINFO_STRING: CURLINFO = 0x100000;
763763
pub const CURLINFO_LONG: CURLINFO = 0x200000;
764764
pub const CURLINFO_DOUBLE: CURLINFO = 0x300000;
765765
pub const CURLINFO_SLIST: CURLINFO = 0x400000;
766+
pub const CURLINFO_PTR: CURLINFO = 0x400000; /* same as SLIST */
767+
pub const CURLINFO_SOCKET: CURLINFO = 0x500000;
768+
pub const CURLINFO_OFF_T: CURLINFO = 0x600000;
766769
pub const CURLINFO_MASK: CURLINFO = 0x0fffff;
767770
pub const CURLINFO_TYPEMASK: CURLINFO = 0xf00000;
768771

@@ -809,6 +812,27 @@ pub const CURLINFO_PRIMARY_PORT: CURLINFO = CURLINFO_LONG + 40;
809812
pub const CURLINFO_LOCAL_IP: CURLINFO = CURLINFO_STRING + 41;
810813
pub const CURLINFO_LOCAL_PORT: CURLINFO = CURLINFO_LONG + 42;
811814
// pub const CURLINFO_TLS_SESSION: CURLINFO = CURLINFO_SLIST + 43;
815+
pub const CURLINFO_ACTIVESOCKET: CURLINFO = CURLINFO_SOCKET + 44;
816+
pub const CURLINFO_TLS_SSL_PTR: CURLINFO = CURLINFO_PTR + 45;
817+
pub const CURLINFO_HTTP_VERSION: CURLINFO = CURLINFO_LONG + 46;
818+
pub const CURLINFO_PROXY_SSL_VERIFYRESULT: CURLINFO = CURLINFO_LONG + 47;
819+
pub const CURLINFO_PROTOCOL: CURLINFO = CURLINFO_LONG + 48;
820+
pub const CURLINFO_SCHEME: CURLINFO = CURLINFO_STRING + 49;
821+
pub const CURLINFO_TOTAL_TIME_T: CURLINFO = CURLINFO_OFF_T + 50;
822+
pub const CURLINFO_NAMELOOKUP_TIME_T: CURLINFO = CURLINFO_OFF_T + 51;
823+
pub const CURLINFO_CONNECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 52;
824+
pub const CURLINFO_PRETRANSFER_TIME_T: CURLINFO = CURLINFO_OFF_T + 53;
825+
pub const CURLINFO_STARTTRANSFER_TIME_T: CURLINFO = CURLINFO_OFF_T + 54;
826+
pub const CURLINFO_REDIRECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 55;
827+
pub const CURLINFO_APPCONNECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 56;
828+
pub const CURLINFO_RETRY_AFTER: CURLINFO = CURLINFO_OFF_T + 57;
829+
pub const CURLINFO_EFFECTIVE_METHOD: CURLINFO = CURLINFO_STRING + 58;
830+
pub const CURLINFO_PROXY_ERROR: CURLINFO = CURLINFO_LONG + 59;
831+
pub const CURLINFO_REFERER: CURLINFO = CURLINFO_STRING + 60;
832+
pub const CURLINFO_CAINFO: CURLINFO = CURLINFO_STRING + 61;
833+
pub const CURLINFO_CAPATH: CURLINFO = CURLINFO_STRING + 62;
834+
pub const CURLINFO_XFER_ID: CURLINFO = CURLINFO_OFF_T + 63;
835+
pub const CURLINFO_CONN_ID: CURLINFO = CURLINFO_OFF_T + 64;
812836

813837
pub type curl_closepolicy = __enum_ty;
814838
pub const CURLCLOSEPOLICY_NONE: curl_closepolicy = 0;

src/easy/handler.rs

+14
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,20 @@ impl<H> Easy2<H> {
31283128
Ok(list::from_raw(list))
31293129
}
31303130
}
3131+
/// Get the last http version number
3132+
///
3133+
/// Corresponds to `CURLINFO_HTTP_VERSION` and may return an error if the
3134+
/// option isn't supported.
3135+
pub fn response_http_version(&self) -> Result<HttpVersion, Error> {
3136+
self.getopt_long(curl_sys::CURLINFO_HTTP_VERSION)
3137+
.map(|c| match c as i32 {
3138+
curl_sys::CURL_HTTP_VERSION_1_0 => HttpVersion::V10,
3139+
curl_sys::CURL_HTTP_VERSION_1_1 => HttpVersion::V11,
3140+
curl_sys::CURL_HTTP_VERSION_2_0 => HttpVersion::V2,
3141+
curl_sys::CURL_HTTP_VERSION_3 => HttpVersion::V3,
3142+
_ => unreachable!("TODO"),
3143+
})
3144+
}
31313145

31323146
/// Wait for pipelining/multiplexing
31333147
///

0 commit comments

Comments
 (0)