Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable logging in rustls and tracing-using dependencies #390

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ dirs = "5.0"
encoding_rs = "0.8.28"
encoding_rs_io = "0.1.7"
flate2 = "1.0.22"
# Add "tracing" feature to hyper once it stabilizes
hyper = { version = "1.2", default-features = false }
indicatif = "0.17"
jsonxf = "1.1.0"
@@ -52,6 +53,11 @@ ruzstd = { version = "0.7", default-features = false, features = ["std"]}
env_logger = { version = "0.11.3", default-features = false, features = ["color", "auto-color", "humantime"] }
log = "0.4.21"

# Enable logging in transitive dependencies.
# The rustls version number should be kept in sync with hyper/reqwest.
rustls = { version = "0.23.14", optional = true, default-features = false, features = ["logging"] }
tracing = { version = "0.1.41", default-features = false, features = ["log"] }

[dependencies.reqwest]
version = "0.12.3"
default-features = false
@@ -85,7 +91,7 @@ http-body-util = "0.1.1"
[features]
default = ["online-tests", "rustls", "network-interface"]
native-tls = ["reqwest/native-tls", "reqwest/native-tls-alpn"]
rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-webpki-roots", "reqwest/rustls-tls-native-roots"]
rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-webpki-roots", "reqwest/rustls-tls-native-roots", "dep:rustls"]

# To be used by platforms that don't support binding to interface via SO_BINDTODEVICE
# Ideally, this would be auto-disabled on platforms that don't need it
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -73,14 +73,15 @@ fn main() {
log::debug!("{args:#?}");

let native_tls = args.native_tls;
let bin_name = args.bin_name.clone();

match run(args) {
Ok(exit_code) => {
process::exit(exit_code);
}
Err(err) => {
log::debug!("{err:#?}");
log::error!("{err:?}");
eprintln!("{bin_name}: error: {err:?}");
let msg = err.root_cause().to_string();
if native_tls && msg == "invalid minimum TLS version for backend" {
eprintln!();
20 changes: 20 additions & 0 deletions tests/cases/logging.rs
Original file line number Diff line number Diff line change
@@ -124,3 +124,23 @@ fn warning_for_non_utf8_redirect() {
.assert()
.stderr("xh: warning: Redirect to invalid URL: \"\\xff\"\n");
}

/// This test should fail if rustls's version gets out of sync in Cargo.toml.
#[cfg(feature = "rustls")]
#[test]
fn rustls_emits_logs() {
let mut server = server::http(|_req| async move {
unreachable!();
});
server.disable_hit_checks();
let cmd = get_command()
.arg("--debug")
.arg(server.base_url().replace("http://", "https://"))
.env_remove("RUST_LOG")
.assert()
.failure();

assert!(std::str::from_utf8(&cmd.get_output().stderr)
.unwrap()
.contains("rustls::"));
}