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 Max Age CURL Option #360

Merged
merged 3 commits into from
Oct 11, 2020
Merged

Add Max Age CURL Option #360

merged 3 commits into from
Oct 11, 2020

Conversation

gsquire
Copy link
Contributor

@gsquire gsquire commented Oct 8, 2020

This would ideally be added to support the feature addition mentioned in sagebind/isahc#93.

I found the constant listed here.

@sagebind
Copy link
Collaborator

sagebind commented Oct 8, 2020

Constants are validated against system libcurl which is dependent on versions. To add an exclusion configuration for a new constant, you can add a new match here:

curl-rust/systest/build.rs

Lines 63 to 156 in badb448

cfg.skip_const(move |s| {
if version < 72 {
match s {
"CURLVERSION_EIGHTH" => return true,
_ => {}
}
}
if version < 70 {
match s {
"CURL_VERSION_HTTP3"
| "CURL_VERSION_BROTLI"
| "CURLVERSION_SEVENTH"
| "CURLVERSION_NOW" => return true,
_ => {}
}
}
if version < 66 {
match s {
"CURL_HTTP_VERSION_3" => return true,
_ => {}
}
}
if version < 65 {
match s {
"CURLVERSION_SIXTH" => return true,
_ => {}
}
}
if version < 64 {
match s {
"CURLE_HTTP2" => return true,
"CURLE_PEER_FAILED_VERIFICATION" => return true,
"CURLE_NO_CONNECTION_AVAILABLE" => return true,
"CURLE_SSL_PINNEDPUBKEYNOTMATCH" => return true,
"CURLE_SSL_INVALIDCERTSTATUS" => return true,
"CURLE_HTTP2_STREAM" => return true,
"CURLE_RECURSIVE_API_CALL" => return true,
_ => {}
}
}
if version < 61 {
match s {
"CURLOPT_PIPEWAIT" => return true,
"CURLE_PEER_FAILED_VERIFICATION" => return true,
_ => {}
}
}
if version < 60 {
match s {
"CURLVERSION_FIFTH" => return true,
_ => {}
}
}
if version < 54 {
match s {
"CURL_SSLVERSION_TLSv1_3"
| "CURLOPT_PROXY_CAINFO"
| "CURLOPT_PROXY_SSLCERT"
| "CURLOPT_PROXY_SSLKEY" => return true,
_ => {}
}
}
if version < 52 {
match s {
"CURLOPT_PROXY_CAPATH" => return true,
_ => {}
}
}
if version < 49 {
match s {
"CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE" | "CURLOPT_CONNECT_TO" => return true,
_ => {}
}
}
if version < 47 {
if s.starts_with("CURL_HTTP_VERSION_2") {
return true;
}
}
if version < 43 {
if s.starts_with("CURLPIPE_") {
return true;
}
}
// OSX doesn't have this yet
s == "CURLSSLOPT_NO_REVOKE" ||
// A lot of curl versions doesn't support unix sockets
s == "CURLOPT_UNIX_SOCKET_PATH" || s == "CURL_VERSION_UNIX_SOCKETS"
});

In this case, CURLOPT_MAXAGE_CONN was added in version 7.65.0. After updating this the tests should pass.

@sagebind
Copy link
Collaborator

sagebind commented Oct 8, 2020

Thanks for the PR! Can we also expose this in the Rust interface? Something like this:

impl Easy2 {
    pub fn maxage_conn(&mut self, maxage: Duration) -> Result<(), Error> {
        // todo
    }
}

See Easy2::tcp_keepidle for an example of how to set a curl option that takes a Duration:

curl-rust/src/easy/handler.rs

Lines 1067 to 1069 in badb448

pub fn tcp_keepidle(&mut self, amt: Duration) -> Result<(), Error> {
self.setopt_long(curl_sys::CURLOPT_TCP_KEEPIDLE, amt.as_secs() as c_long)
}

We also more-or-less copy-paste every function into Easy to keep Easy2 and Easy in sync.

curl-sys/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@sagebind sagebind left a comment

Choose a reason for hiding this comment

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

Awesome, looks good to me. Thanks for contributing!

@alexcrichton alexcrichton merged commit 454a720 into alexcrichton:master Oct 11, 2020
@gsquire gsquire deleted the add-max-age-option branch October 13, 2020 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants