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 support to configure timeout of Expect 100 behaviour #311

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ unstable-interceptors = []

[dependencies]
crossbeam-utils = "0.8"
curl = "0.4.34"
curl = "0.4.35"
curl-sys = "0.4.37"
futures-lite = "1.11"
http = "0.2.1"
Expand Down
35 changes: 35 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,41 @@ pub trait Configurable: request::WithRequestConfig {
})
}

/// 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 headers 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.
/// More info: https://curl.se/libcurl/c/CURLOPT_EXPECT_100_TIMEOUT_MS.html
///
/// If not set, a default timeout of 1 second will be used.
///
/// # Examples
///
/// ```no_run
/// use std::time::Duration;
/// let response = Request::post("https://httpbin.org/post")
/// .expect_100_timeout(Duration::from_millis(0)) //Send request body immediately
/// .body(())?
/// .send()?;
///
/// let response = Request::post("https://httpbin.org/post")
/// .expect_100_timeout(Duration::from_millis(100)) //Wait for a maximum of 100ms before sending body
/// .body(())?
/// .send()?;
/// ```
fn expect_100_timeout(self, timeout: Duration) -> Self {
self.with_config(move |config| {
config.expect_100_timeout = Some(timeout);
})
}

/// Configure how the use of HTTP versions should be negotiated with the
/// server.
///
Expand Down
5 changes: 5 additions & 0 deletions src/config/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ define_request_config! {
// Used by curl
timeout: Option<Duration>,
connect_timeout: Option<Duration>,
expect_100_timeout: Option<Duration>,
version_negotiation: Option<VersionNegotiation>,
automatic_decompression: Option<bool>,
authentication: Option<Authentication>,
Expand Down Expand Up @@ -102,6 +103,10 @@ impl SetOpt for RequestConfig {
easy.connect_timeout(timeout)?;
}

if let Some(timeout) = self.expect_100_timeout {
easy.expect_100_timeout(timeout)?;
}

if let Some(negotiation) = self.version_negotiation.as_ref() {
negotiation.set_opt(easy)?;
}
Expand Down