Skip to content

Commit

Permalink
feat: add connect-timeout option per request
Browse files Browse the repository at this point in the history
Added a connect-timeout option to allow users to specify a
connect-timeout for each request in a hurl file.

Closes Orange-OpenSource#3163
  • Loading branch information
zikani03 authored and hurl-bot committed Oct 15, 2024
1 parent 5a52728 commit a3e9b1a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/hurl/src/runner/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ pub fn get_entry_options(
let value = eval_template(value, variables)?;
entry_options.connects_to.push(value);
}
OptionKind::ConnectTimeout(value) => {
let value =
eval_duration_option(value, variables, DurationUnit::MilliSecond)?;
entry_options.connect_timeout = value;
}
OptionKind::Delay(value) => {
let value =
eval_duration_option(value, variables, DurationUnit::MilliSecond)?;
Expand Down
3 changes: 3 additions & 0 deletions packages/hurl_core/src/ast/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ pub enum OptionKind {
ClientKey(Template),
Compressed(BooleanOption),
ConnectTo(Template),
ConnectTimeout(DurationOption),
Delay(DurationOption),
Http10(BooleanOption),
Http11(BooleanOption),
Expand Down Expand Up @@ -765,6 +766,7 @@ impl OptionKind {
OptionKind::ClientKey(_) => "key",
OptionKind::Compressed(_) => "compressed",
OptionKind::ConnectTo(_) => "connect-to",
OptionKind::ConnectTimeout(_) => "connect-timeout",
OptionKind::Delay(_) => "delay",
OptionKind::FollowLocation(_) => "location",
OptionKind::FollowLocationTrusted(_) => "location-trusted",
Expand Down Expand Up @@ -803,6 +805,7 @@ impl OptionKind {
OptionKind::ClientKey(filename) => filename.to_string(),
OptionKind::Compressed(value) => value.to_string(),
OptionKind::ConnectTo(value) => value.to_string(),
OptionKind::ConnectTimeout(value) => value.to_string(),
OptionKind::Delay(value) => value.to_string(),
OptionKind::FollowLocation(value) => value.to_string(),
OptionKind::FollowLocationTrusted(value) => value.to_string(),
Expand Down
1 change: 1 addition & 0 deletions packages/hurl_core/src/format/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl HtmlFormatter {
OptionKind::ClientKey(filename) => self.fmt_filename(filename),
OptionKind::Compressed(value) => self.fmt_bool_option(value),
OptionKind::ConnectTo(value) => self.fmt_template(value),
OptionKind::ConnectTimeout(value) => self.fmt_duration_option(value),
OptionKind::Delay(value) => self.fmt_duration_option(value),
OptionKind::FollowLocation(value) => self.fmt_bool_option(value),
OptionKind::FollowLocationTrusted(value) => self.fmt_bool_option(value),
Expand Down
6 changes: 6 additions & 0 deletions packages/hurl_core/src/parser/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<EntryOption> {
"cert" => option_cert(reader)?,
"compressed" => option_compressed(reader)?,
"connect-to" => option_connect_to(reader)?,
"connect-timeout" => option_connect_timeout(reader)?,
"delay" => option_delay(reader)?,
"insecure" => option_insecure(reader)?,
"http1.0" => option_http_10(reader)?,
Expand Down Expand Up @@ -118,6 +119,11 @@ fn option_connect_to(reader: &mut Reader) -> ParseResult<OptionKind> {
Ok(OptionKind::ConnectTo(value))
}

fn option_connect_timeout(reader: &mut Reader) -> ParseResult<OptionKind> {
let value = duration_option(reader)?;
Ok(OptionKind::ConnectTimeout(value))
}

fn option_delay(reader: &mut Reader) -> ParseResult<OptionKind> {
let value = duration_option(reader)?;
Ok(OptionKind::Delay(value))
Expand Down
1 change: 1 addition & 0 deletions packages/hurlfmt/src/format/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl ToJson for EntryOption {
OptionKind::ClientKey(filename) => JValue::String(filename.to_string()),
OptionKind::Compressed(value) => value.to_json(),
OptionKind::ConnectTo(value) => JValue::String(value.to_string()),
OptionKind::ConnectTimeout(value) => value.to_json(),
OptionKind::Delay(value) => value.to_json(),
OptionKind::FollowLocation(value) => value.to_json(),
OptionKind::FollowLocationTrusted(value) => value.to_json(),
Expand Down
1 change: 1 addition & 0 deletions packages/hurlfmt/src/format/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ impl Tokenizable for OptionKind {
OptionKind::ClientKey(filename) => filename.tokenize(),
OptionKind::Compressed(value) => value.tokenize(),
OptionKind::ConnectTo(value) => value.tokenize(),
OptionKind::ConnectTimeout(value) => value.tokenize(),
OptionKind::Delay(value) => value.tokenize(),
OptionKind::FollowLocation(value) => value.tokenize(),
OptionKind::FollowLocationTrusted(value) => value.tokenize(),
Expand Down

0 comments on commit a3e9b1a

Please sign in to comment.