Skip to content

Commit c68c933

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 c68c933

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
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

+27-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ pub enum IpResolve {
428428

429429
/// Possible values to pass to the `http_version` method.
430430
#[non_exhaustive]
431-
#[derive(Debug, Clone, Copy)]
431+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
432432
pub enum HttpVersion {
433433
/// We don't care what http version to use, and we'd like the library to
434434
/// choose the best possible for us.
@@ -3128,6 +3128,23 @@ 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 get_http_version(&self) -> Result<HttpVersionInfo, Error> {
3136+
self.getopt_long(curl_sys::CURLINFO_HTTP_VERSION).map(|c| {
3137+
HttpVersionInfo::HttpVersion(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_2TLS => HttpVersion::V2TLS,
3142+
curl_sys::CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE => HttpVersion::V2PriorKnowledge,
3143+
curl_sys::CURL_HTTP_VERSION_3 => HttpVersion::V3,
3144+
c => return HttpVersionInfo::Unknown(c),
3145+
})
3146+
})
3147+
}
31313148

31323149
/// Wait for pipelining/multiplexing
31333150
///
@@ -3989,3 +4006,12 @@ impl fmt::Debug for PostRedirections {
39894006
.finish()
39904007
}
39914008
}
4009+
4010+
/// Possible values returned by [`Easy2::get_http_version()`].
4011+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
4012+
pub enum HttpVersionInfo {
4013+
/// Known HTTP version described by [`HttpVersion`].
4014+
HttpVersion(HttpVersion),
4015+
/// Invalid or unknown version returned for [`curl_sys::CURLINFO_HTTP_VERSION`].
4016+
Unknown(i32),
4017+
}

0 commit comments

Comments
 (0)