Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new CURLINFO_ constants and fn response_http_version() #539

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 27 additions & 1 deletion src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub enum IpResolve {

/// Possible values to pass to the `http_version` method.
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HttpVersion {
Comment on lines -431 to 432
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why simple enums have to be compared by match/if let and are not allowed to be used in simple == by deriving these quite-standard Eq traits. Intentional or oversight?

/// We don't care what http version to use, and we'd like the library to
/// choose the best possible for us.
Expand Down Expand Up @@ -3128,6 +3128,23 @@ 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 get_http_version(&self) -> Result<HttpVersionInfo, Error> {
self.getopt_long(curl_sys::CURLINFO_HTTP_VERSION).map(|c| {
HttpVersionInfo::HttpVersion(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_2TLS => HttpVersion::V2TLS,
curl_sys::CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE => HttpVersion::V2PriorKnowledge,
curl_sys::CURL_HTTP_VERSION_3 => HttpVersion::V3,
c => return HttpVersionInfo::Unknown(c),
})
})
}

/// Wait for pipelining/multiplexing
///
Expand Down Expand Up @@ -3989,3 +4006,12 @@ impl fmt::Debug for PostRedirections {
.finish()
}
}

/// Possible values returned by [`Easy2::get_http_version()`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum HttpVersionInfo {
/// Known HTTP version described by [`HttpVersion`].
HttpVersion(HttpVersion),
/// Invalid or unknown version returned for [`curl_sys::CURLINFO_HTTP_VERSION`].
Unknown(i32),
}
Loading