Skip to content

Commit

Permalink
Add a HTTP connect timeout - default 10s (#1584)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman authored Jun 3, 2024
1 parent c6db74a commit 858e3f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/service-client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl HttpClient {
let mut http_connector = HttpConnector::new();
http_connector.enforce_http(false);
http_connector.set_nodelay(true);
http_connector.set_connect_timeout(Some(options.connect_timeout.into()));

HttpClient::new(
builder.build::<_, hyper::Body>(ProxyConnector::new(
Expand Down
26 changes: 25 additions & 1 deletion crates/types/src/config/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde_with::serde_as;

/// # HTTP client options
#[serde_as]
#[derive(Debug, Default, Clone, Serialize, Deserialize, derive_builder::Builder)]
#[derive(Debug, Clone, Serialize, Deserialize, derive_builder::Builder)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schemars", schemars(rename = "HttpClientOptions", default))]
#[builder(default)]
Expand All @@ -37,6 +37,30 @@ pub struct HttpOptions {
/// Can be overridden by the `HTTP_PROXY` environment variable.
#[cfg_attr(feature = "schemars", schemars(with = "Option<String>"))]
pub http_proxy: Option<ProxyUri>,
/// # Connect timeout
///
/// How long to wait for a TCP connection to be established before considering
/// it a failed attempt.
#[serde_as(as = "serde_with::DisplayFromStr")]
#[cfg_attr(feature = "schemars", schemars(with = "String"))]
pub connect_timeout: humantime::Duration,
}

impl Default for HttpOptions {
fn default() -> Self {
Self {
http_keep_alive_options: Http2KeepAliveOptions::default(),
http_proxy: None,
connect_timeout: HttpOptions::default_connect_timeout(),
}
}
}

impl HttpOptions {
#[inline]
fn default_connect_timeout() -> humantime::Duration {
(Duration::from_secs(10)).into()
}
}

/// # HTTP/2 Keep alive options
Expand Down

0 comments on commit 858e3f6

Please sign in to comment.