diff --git a/README.md b/README.md index c6ae32e3..03605210 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Arguments: Options: -n - Number of requests to run. [default: 200] + Number of requests to run. Accepts plain numbers or suffixes: k = 1,000, m = 1,000,000 (e.g. 10k, 1m). [default: 200] -c Number of connections to run concurrently. You may should increase limit to number of open files for larger `-c`. [default: 50] -p @@ -148,6 +148,8 @@ Options: Custom Proxy HTTP header. Examples: --proxy-header "foo: bar" -t Timeout for each request. Default to infinite. + --connect-timeout + Timeout for establishing a new connection. Default to 5s. -A HTTP Accept Header. -d diff --git a/src/client.rs b/src/client.rs index a60f67aa..0c556266 100644 --- a/src/client.rs +++ b/src/client.rs @@ -195,6 +195,7 @@ pub struct Client { pub proxy_headers: http::header::HeaderMap, pub dns: Dns, pub timeout: Option, + pub connect_timeout: std::time::Duration, pub redirect_limit: usize, pub disable_keepalive: bool, pub proxy_url: Option, @@ -234,6 +235,7 @@ impl Default for Client { connect_to: Vec::new(), }, timeout: None, + connect_timeout: std::time::Duration::from_secs(5), redirect_limit: 0, disable_keepalive: false, proxy_url: None, @@ -452,8 +454,7 @@ impl Client { rng: &mut R, http_version: http::Version, ) -> Result<(Instant, Stream), ClientError> { - // TODO: Allow the connect timeout to be configured - let timeout_duration = tokio::time::Duration::from_secs(5); + let timeout_duration = self.connect_timeout; #[cfg(feature = "http3")] if http_version == http::Version::HTTP_3 { diff --git a/src/lib.rs b/src/lib.rs index 4842eb69..28b86961 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,6 +169,12 @@ Note: If qps is specified, burst will be ignored", proxy_headers: Vec, #[arg(help = "Timeout for each request. Default to infinite.", short = 't')] timeout: Option, + #[arg( + help = "Timeout for establishing a new connection. Default to 5s.", + long = "connect-timeout", + default_value = "5s" + )] + connect_timeout: humantime::Duration, #[arg(help = "HTTP Accept Header.", short = 'A')] accept_header: Option, #[arg(help = "HTTP request body.", short = 'd', conflicts_with_all = ["body_path", "body_path_lines", "form"])] @@ -655,6 +661,7 @@ pub async fn run(mut opts: Opts) -> anyhow::Result<()> { connect_to: opts.connect_to, }, timeout: opts.timeout.map(|d| d.into()), + connect_timeout: opts.connect_timeout.into(), redirect_limit: opts.redirect, disable_keepalive: opts.disable_keepalive, proxy_url: opts.proxy,