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 an option to set the expect 100 timeout #376

Merged
merged 1 commit into from
Feb 23, 2021
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Cargo.lock
target/
.idea/
1 change: 1 addition & 0 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
// pub const CURLOPT_DNS_LOCAL_IP4: CURLoption = CURLOPTTYPE_OBJECTPOINT + 222;
// pub const CURLOPT_DNS_LOCAL_IP6: CURLoption = CURLOPTTYPE_OBJECTPOINT + 223;
// pub const CURLOPT_LOGIN_OPTIONS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 224;
pub const CURLOPT_EXPECT_100_TIMEOUT_MS: CURLoption = CURLOPTTYPE_LONG + 227;
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;
pub const CURLOPT_CONNECT_TO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 243;
Expand Down
27 changes: 27 additions & 0 deletions src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,33 @@ impl<H> Easy2<H> {
// =========================================================================
// getters

/// Set maximum time to wait for Expect 100 request before sending body.
///
/// `curl` has internal heuristics that trigger the use of a `Expect`
/// header for large enough request bodies where the client first sends the
/// request header along with an `Expect: 100-continue` header. The server
/// is supposed to validate the headers and respond with a `100` response
/// status code after which `curl` will send the actual request body.
///
/// However, if the server does not respond to the initial request
/// within `CURLOPT_EXPECT_100_TIMEOUT_MS` then `curl` will send the
/// request body anyways.
///
/// The best-case scenario is where the request is invalid and the server
/// replies with a `417 Expectation Failed` without having to wait for or process
/// the request body at all. However, this behaviour can also lead to higher
/// total latency since in the best case, an additional server roundtrip is required
/// and in the worst case, the request is delayed by `CURLOPT_EXPECT_100_TIMEOUT_MS`.
///
/// More info: https://curl.se/libcurl/c/CURLOPT_EXPECT_100_TIMEOUT_MS.html
///
/// By default this option is not set and corresponds to
/// `CURLOPT_EXPECT_100_TIMEOUT_MS`.
pub fn expect_100_timeout(&mut self, timeout: Duration) -> Result<(), Error> {
let ms = timeout.as_secs() * 1000 + (timeout.subsec_nanos() / 1_000_000) as u64;
self.setopt_long(curl_sys::CURLOPT_EXPECT_100_TIMEOUT_MS, ms as c_long)
}

/// Get info on unmet time conditional
///
/// Returns if the condition provided in the previous request didn't match
Expand Down