Merge branch 'master' into header-and-querystring-from-file

This commit is contained in:
ducaale 2022-12-27 14:39:36 +02:00
commit 0817ddefa6
5 changed files with 63 additions and 21 deletions

View File

@ -81,11 +81,15 @@ environment variable is to rename the binary to either http or https.
.BR REQUESTS_CA_BUNDLE ", " CURL_CA_BUNDLE
Sets a custom CA bundle path.
.TP
.B HTTPS_PROXY
.BR http_proxy "=[protocol://]<host>[:port]"
Sets the proxy server to use for HTTP.
.TP
.BR HTTPS_PROXY "=[protocol://]<host>[:port]"
Sets the proxy server to use for HTTPS.
.TP
.B http_proxy
Sets the proxy server to use for HTTP.
.B NO_PROXY
List of comma-separated hosts for which to ignore the other proxy environment
variables. "*" matches all host names.
.TP
.B NETRC
Location of the .netrc file.

View File

@ -1,4 +1,4 @@
.TH XH 1 2022-11-13 0.17.0 "User Commands"
.TH XH 1 2022-12-13 0.17.0 "User Commands"
.SH NAME
xh \- Friendly and fast tool for sending HTTP requests
@ -326,11 +326,15 @@ environment variable is to rename the binary to either http or https.
.BR REQUESTS_CA_BUNDLE ", " CURL_CA_BUNDLE
Sets a custom CA bundle path.
.TP
.B HTTPS_PROXY
.BR http_proxy "=[protocol://]<host>[:port]"
Sets the proxy server to use for HTTP.
.TP
.BR HTTPS_PROXY "=[protocol://]<host>[:port]"
Sets the proxy server to use for HTTPS.
.TP
.B http_proxy
Sets the proxy server to use for HTTP.
.B NO_PROXY
List of comma-separated hosts for which to ignore the other proxy environment
variables. "*" matches all host names.
.TP
.B NETRC
Location of the .netrc file.

View File

@ -814,7 +814,7 @@ fn generate_manpages(mut app: clap::Command, rest_args: Vec<String>) -> Error {
header.push(roman("] | "));
header.push(italic("TOKEN"));
} else {
header.push(italic(&value.join(" ")));
header.push(italic(value.join(" ")));
}
}
let mut body = vec![];
@ -1050,13 +1050,18 @@ impl FromStr for Timeout {
type Err = anyhow::Error;
fn from_str(sec: &str) -> anyhow::Result<Timeout> {
let pos_sec: f64 = match sec.parse::<f64>() {
Ok(sec) if sec.is_sign_positive() => sec,
_ => return Err(anyhow!("Invalid seconds as connection timeout")),
};
let dur = Duration::from_secs_f64(pos_sec);
Ok(Timeout(dur))
match f64::from_str(sec) {
Ok(s) if !s.is_nan() => {
if s.is_sign_negative() {
Err(anyhow!("Connection timeout is negative"))
} else if s >= Duration::MAX.as_secs_f64() || s.is_infinite() {
Err(anyhow!("Connection timeout is too big"))
} else {
Ok(Timeout(Duration::from_secs_f64(s)))
}
}
_ => Err(anyhow!("Connection timeout is not a valid number")),
}
}
}

View File

@ -379,7 +379,7 @@ impl RequestItems {
file_type,
file_name_header,
} => {
let mut part = file_to_part(expand_tilde(&file_name))?;
let mut part = file_to_part(expand_tilde(file_name))?;
if let Some(file_type) = file_type {
part = part.mime_str(&file_type)?;
}

View File

@ -14,7 +14,6 @@ use std::time::Duration;
use assert_cmd::cmd::Command;
use indoc::indoc;
use predicates::boolean::PredicateBooleanExt;
use predicates::function::function;
use predicates::str::contains;
use tempfile::{tempdir, NamedTempFile, TempDir};
@ -666,7 +665,31 @@ fn timeout_invalid() {
.args(["--timeout=-0.01", "--offline", ":"])
.assert()
.failure()
.stderr(contains("Invalid seconds as connection timeout"));
.stderr(contains("Connection timeout is negative"));
get_command()
.args(["--timeout=18446744073709552000", "--offline", ":"])
.assert()
.failure()
.stderr(contains("Connection timeout is too big"));
get_command()
.args(["--timeout=inf", "--offline", ":"])
.assert()
.failure()
.stderr(contains("Connection timeout is too big"));
get_command()
.args(["--timeout=NaN", "--offline", ":"])
.assert()
.failure()
.stderr(contains("Connection timeout is not a valid number"));
get_command()
.args(["--timeout=SEC", "--offline", ":"])
.assert()
.failure()
.stderr(contains("Connection timeout is not a valid number"));
}
#[test]
@ -984,7 +1007,7 @@ fn netrc_file_user_password_auth() {
let homedir = TempDir::new().unwrap();
let netrc_path = homedir.path().join(netrc_file);
let mut netrc = File::create(&netrc_path).unwrap();
let mut netrc = File::create(netrc_path).unwrap();
writeln!(
netrc,
"machine {}\nlogin user\npassword pass",
@ -1127,9 +1150,12 @@ fn proxy_multiple_valid_proxies() {
cmd.assert().success();
}
#[cfg(feature = "online-tests")]
// temporarily disabled for builds not using rustls
#[cfg(all(feature = "online-tests", feature = "rustls"))]
#[test]
fn verify_default_yes() {
use predicates::boolean::PredicateBooleanExt;
get_command()
.args(["-v", "https://self-signed.badssl.com"])
.assert()
@ -1139,9 +1165,12 @@ fn verify_default_yes() {
.stderr(contains("UnknownIssuer").or(contains("self signed certificate")));
}
#[cfg(feature = "online-tests")]
// temporarily disabled for builds not using rustls
#[cfg(all(feature = "online-tests", feature = "rustls"))]
#[test]
fn verify_explicit_yes() {
use predicates::boolean::PredicateBooleanExt;
get_command()
.args(["-v", "--verify=yes", "https://self-signed.badssl.com"])
.assert()