diff --git a/README.md b/README.md index 60cc033b6f9..733b52db272 100644 --- a/README.md +++ b/README.md @@ -1457,10 +1457,10 @@ will follow a redirection only for the second entry. | --connect-to <HOST1:PORT1:HOST2:PORT2> | For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead. This option can be used several times in a command line.

See also [`--resolve`](#resolve).
| | --digest | Tell Hurl to use HTTP Digest authentication
| | -H, --header <NAME:VALUE> | Add an extra header to include in information sent. Can be used several times in a command.

Do not add newlines or carriage returns.

Environment variables: HURL_HEADER='name1:value1|name2:value2' (headers are separated by |)
| -| -0, --http1.0 | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.
| -| --http1.1 | Tells Hurl to use HTTP version 1.1.
| -| --http2 | Tells Hurl to use HTTP version 2.
For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.
For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.
| -| --http3 | Tells Hurl to try HTTP/3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs.
| +| -0, --http1.0 | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.

Environment variables: HURL_HTTP10
| +| --http1.1 | Tells Hurl to use HTTP version 1.1.

Environment variables: HURL_HTTP11
| +| --http2 | Tells Hurl to use HTTP version 2.
For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.
For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.

Environment variables: HURL_HTTP2
| +| --http3 | Tells Hurl to try HTTP version 3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs.

Environment variables: HURL_HTTP3
| | -k, --insecure | This option explicitly allows Hurl to perform "insecure" SSL connections and transfers.
| | -4, --ipv4 | This option tells Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6.

Environment variables: HURL_IPV4
| | -6, --ipv6 | This option tells Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4.

Environment variables: HURL_IPV6
| diff --git a/docs/manual.md b/docs/manual.md index 630bbf8320c..07b674da91a 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -159,10 +159,10 @@ will follow a redirection only for the second entry. | --connect-to <HOST1:PORT1:HOST2:PORT2> | For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead. This option can be used several times in a command line.

See also [`--resolve`](#resolve).
| | --digest | Tell Hurl to use HTTP Digest authentication
| | -H, --header <NAME:VALUE> | Add an extra header to include in information sent. Can be used several times in a command.

Do not add newlines or carriage returns.

Environment variables: HURL_HEADER='name1:value1|name2:value2' (headers are separated by |)
| -| -0, --http1.0 | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.
| -| --http1.1 | Tells Hurl to use HTTP version 1.1.
| -| --http2 | Tells Hurl to use HTTP version 2.
For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.
For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.
| -| --http3 | Tells Hurl to try HTTP/3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs.
| +| -0, --http1.0 | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.

Environment variables: HURL_HTTP10
| +| --http1.1 | Tells Hurl to use HTTP version 1.1.

Environment variables: HURL_HTTP11
| +| --http2 | Tells Hurl to use HTTP version 2.
For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.
For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.

Environment variables: HURL_HTTP2
| +| --http3 | Tells Hurl to try HTTP version 3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs.

Environment variables: HURL_HTTP3
| | -k, --insecure | This option explicitly allows Hurl to perform "insecure" SSL connections and transfers.
| | -4, --ipv4 | This option tells Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6.

Environment variables: HURL_IPV4
| | -6, --ipv6 | This option tells Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4.

Environment variables: HURL_IPV6
| diff --git a/docs/manual/hurl.1 b/docs/manual/hurl.1 index 05bca7a81aa..932cfeed163 100644 --- a/docs/manual/hurl.1 +++ b/docs/manual/hurl.1 @@ -184,19 +184,27 @@ Environment variables: HURL_HEADER='name1:value1|name2:value2' (headers are sepa Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version. +Environment variables: HURL_HTTP10 + .IP "--http1.1 " Tells Hurl to use HTTP version 1.1. +Environment variables: HURL_HTTP11 + .IP "--http2 " Tells Hurl to use HTTP version 2. For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default. For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header. +Environment variables: HURL_HTTP2 + .IP "--http3 " -Tells Hurl to try HTTP/3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs. +Tells Hurl to try HTTP version 3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs. + +Environment variables: HURL_HTTP3 .IP "-k, --insecure " diff --git a/docs/manual/hurl.md b/docs/manual/hurl.md index 0e9403dcea3..d2ec35d309f 100644 --- a/docs/manual/hurl.md +++ b/docs/manual/hurl.md @@ -202,19 +202,27 @@ Environment variables: HURL_HEADER='name1:value1|name2:value2' (headers are sepa Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version. +Environment variables: HURL_HTTP10 + #### --http1.1 {#http11} Tells Hurl to use HTTP version 1.1. +Environment variables: HURL_HTTP11 + #### --http2 {#http2} Tells Hurl to use HTTP version 2. For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default. For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header. +Environment variables: HURL_HTTP2 + #### --http3 {#http3} -Tells Hurl to try HTTP/3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs. +Tells Hurl to try HTTP version 3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs. + +Environment variables: HURL_HTTP3 #### -k, --insecure {#insecure} diff --git a/docs/spec/options/hurl/http10.option b/docs/spec/options/hurl/http10.option index 1cf610f74a6..54b9cffcf7e 100644 --- a/docs/spec/options/hurl/http10.option +++ b/docs/spec/options/hurl/http10.option @@ -3,5 +3,6 @@ long: http1.0 short: 0 help: Tell Hurl to use HTTP version 1.0 help_heading: HTTP options +env_var: HURL_HTTP10 --- Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version. diff --git a/docs/spec/options/hurl/http11.option b/docs/spec/options/hurl/http11.option index a89f5ae619c..e5a7bfb071c 100644 --- a/docs/spec/options/hurl/http11.option +++ b/docs/spec/options/hurl/http11.option @@ -2,5 +2,6 @@ name: http11 long: http1.1 help: Tell Hurl to use HTTP version 1.1 help_heading: HTTP options +env_var: HURL_HTTP11 --- Tells Hurl to use HTTP version 1.1. diff --git a/docs/spec/options/hurl/http2.option b/docs/spec/options/hurl/http2.option index f9a8271bb2a..98a649ebc50 100644 --- a/docs/spec/options/hurl/http2.option +++ b/docs/spec/options/hurl/http2.option @@ -2,6 +2,7 @@ name: http2 long: http2 help: Tell Hurl to use HTTP version 2 help_heading: HTTP options +env_var: HURL_HTTP2 --- Tells Hurl to use HTTP version 2. For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default. diff --git a/docs/spec/options/hurl/http3.option b/docs/spec/options/hurl/http3.option index b489c38beff..b04214a2fea 100644 --- a/docs/spec/options/hurl/http3.option +++ b/docs/spec/options/hurl/http3.option @@ -2,5 +2,6 @@ name: http3 long: http3 help: Tell Hurl to use HTTP version 3 help_heading: HTTP options +env_var: HURL_HTTP3 --- -Tells Hurl to try HTTP/3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs. +Tells Hurl to try HTTP version 3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs. diff --git a/integration/hurl/tests_ok/http_version/http_version_10_env_var.ps1 b/integration/hurl/tests_ok/http_version/http_version_10_env_var.ps1 new file mode 100755 index 00000000000..52c01c4ef05 --- /dev/null +++ b/integration/hurl/tests_ok/http_version/http_version_10_env_var.ps1 @@ -0,0 +1,5 @@ +Set-StrictMode -Version latest +$ErrorActionPreference = 'Stop' + +$env:HURL_HTTP10 = '1' +hurl tests_ok/http_version/http_version_10.hurl diff --git a/integration/hurl/tests_ok/http_version/http_version_10_env_var.sh b/integration/hurl/tests_ok/http_version/http_version_10_env_var.sh new file mode 100755 index 00000000000..c9656719110 --- /dev/null +++ b/integration/hurl/tests_ok/http_version/http_version_10_env_var.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -Eeuo pipefail + +export HURL_HTTP10=1 +hurl tests_ok/http_version/http_version_10.hurl diff --git a/integration/hurl/tests_ok/http_version/http_version_11_env_var.ps1 b/integration/hurl/tests_ok/http_version/http_version_11_env_var.ps1 new file mode 100755 index 00000000000..650d829fa53 --- /dev/null +++ b/integration/hurl/tests_ok/http_version/http_version_11_env_var.ps1 @@ -0,0 +1,5 @@ +Set-StrictMode -Version latest +$ErrorActionPreference = 'Stop' + +$env:HURL_HTTP11 = '1' +hurl tests_ok/http_version/http_version_11.hurl diff --git a/integration/hurl/tests_ok/http_version/http_version_11_env_var.sh b/integration/hurl/tests_ok/http_version/http_version_11_env_var.sh new file mode 100755 index 00000000000..c2d73987d8c --- /dev/null +++ b/integration/hurl/tests_ok/http_version/http_version_11_env_var.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -Eeuo pipefail + +export HURL_HTTP11=1 +hurl tests_ok/http_version/http_version_11.hurl diff --git a/packages/hurl/README.md b/packages/hurl/README.md index f339a3bb299..cc4910f7361 100644 --- a/packages/hurl/README.md +++ b/packages/hurl/README.md @@ -1457,10 +1457,10 @@ will follow a redirection only for the second entry. | --connect-to <HOST1:PORT1:HOST2:PORT2> | For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead. This option can be used several times in a command line.

See also [`--resolve`](#resolve).
| | --digest | Tell Hurl to use HTTP Digest authentication
| | -H, --header <NAME:VALUE> | Add an extra header to include in information sent. Can be used several times in a command.

Do not add newlines or carriage returns.

Environment variables: HURL_HEADER='name1:value1|name2:value2' (headers are separated by |)
| -| -0, --http1.0 | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.
| -| --http1.1 | Tells Hurl to use HTTP version 1.1.
| -| --http2 | Tells Hurl to use HTTP version 2.
For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.
For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.
| -| --http3 | Tells Hurl to try HTTP/3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs.
| +| -0, --http1.0 | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.

Environment variables: HURL_HTTP10
| +| --http1.1 | Tells Hurl to use HTTP version 1.1.

Environment variables: HURL_HTTP11
| +| --http2 | Tells Hurl to use HTTP version 2.
For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.
For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.

Environment variables: HURL_HTTP2
| +| --http3 | Tells Hurl to try HTTP version 3 to the host in the URL, but fallback to earlier HTTP versions if the HTTP/3 connection establishment fails. HTTP/3 is only available for HTTPS and not for HTTP URLs.

Environment variables: HURL_HTTP3
| | -k, --insecure | This option explicitly allows Hurl to perform "insecure" SSL connections and transfers.
| | -4, --ipv4 | This option tells Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6.

Environment variables: HURL_IPV4
| | -6, --ipv6 | This option tells Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4.

Environment variables: HURL_IPV6
| diff --git a/packages/hurl/src/cli/options/context.rs b/packages/hurl/src/cli/options/context.rs index 8bdc6270931..63311fffd50 100644 --- a/packages/hurl/src/cli/options/context.rs +++ b/packages/hurl/src/cli/options/context.rs @@ -54,6 +54,10 @@ pub const HURL_DELAY: &str = "HURL_DELAY"; pub const HURL_ERROR_FORMAT: &str = "HURL_ERROR_FORMAT"; pub const HURL_NO_COLOR: &str = "HURL_NO_COLOR"; pub const HURL_HEADER: &str = "HURL_HEADER"; +pub const HURL_HTTP10: &str = "HURL_HTTP10"; +pub const HURL_HTTP11: &str = "HURL_HTTP11"; +pub const HURL_HTTP2: &str = "HURL_HTTP2"; +pub const HURL_HTTP3: &str = "HURL_HTTP3"; pub const HURL_IPV4: &str = "HURL_IPV4"; pub const HURL_IPV6: &str = "HURL_IPV6"; pub const HURL_VARIABLE_PREFIX: &str = "HURL_VARIABLE_"; @@ -120,7 +124,7 @@ impl RunContext { self.get_env_var_bool(HURL_CONTINUE_ON_ERROR) } - /// Returns the env var for connect timeout duration. + /// Returns the env var for delay duration. pub fn delay_env_var(&self) -> Option<&str> { self.hurl_env_vars.get(HURL_DELAY).map(|v| v.as_str()) } @@ -140,6 +144,26 @@ impl RunContext { self.hurl_env_vars.get(HURL_HEADER).map(|v| v.as_str()) } + /// Returns the env var for using HTTP/1.0. + pub fn http10_env_var(&self) -> Option { + self.get_env_var_bool(HURL_HTTP10) + } + + /// Returns the env var for using HTTP/1.1. + pub fn http11_env_var(&self) -> Option { + self.get_env_var_bool(HURL_HTTP11) + } + + /// Returns the env var for using HTTP/2. + pub fn http2_env_var(&self) -> Option { + self.get_env_var_bool(HURL_HTTP2) + } + + /// Returns the env var for using HTTP/3. + pub fn http3_env_var(&self) -> Option { + self.get_env_var_bool(HURL_HTTP3) + } + /// Returns the env var for IPv4 resolution. pub fn ipv4_env_var(&self) -> Option { self.get_env_var_bool(HURL_IPV4) diff --git a/packages/hurl/src/cli/options/env_vars.rs b/packages/hurl/src/cli/options/env_vars.rs index f6eb9f165d3..6ef9f80d249 100644 --- a/packages/hurl/src/cli/options/env_vars.rs +++ b/packages/hurl/src/cli/options/env_vars.rs @@ -22,7 +22,7 @@ use super::variables::TypeKind; use super::{ context::HURL_CONNECT_TIMEOUT, context::HURL_ERROR_FORMAT, context::HURL_HEADER, context::HURL_MAX_TIME, context::HURL_VERBOSITY, duration, secret, variables, CliOptions, - CliOptionsError, ErrorFormat, IpResolve, RunContext, Verbosity, + CliOptionsError, ErrorFormat, HttpVersion, IpResolve, RunContext, Verbosity, }; use crate::cli::options::context::HURL_DELAY; use hurl::runner::Value; @@ -64,6 +64,30 @@ pub fn parse_env_vars( } options.headers.extend(headers); } + if let Some(http3) = context.http3_env_var() { + if http3 { + options.http_version = Some(HttpVersion::V3); + } else { + options.http_version = Some(HttpVersion::V2); + } + } + if let Some(http2) = context.http2_env_var() { + if http2 { + options.http_version = Some(HttpVersion::V2); + } else { + options.http_version = Some(HttpVersion::V11); + } + } + if let Some(http11) = context.http11_env_var() { + if http11 { + options.http_version = Some(HttpVersion::V11); + } else { + options.http_version = Some(HttpVersion::V10); + } + } + if let Some(true) = context.http10_env_var() { + options.http_version = Some(HttpVersion::V10); + } if let Some(ipv4) = context.ipv4_env_var() { if ipv4 { options.ip_resolve = Some(IpResolve::IpV4);