Skip to content

Commit

Permalink
Merge pull request #390 from blyxxyz/log-dependencies
Browse files Browse the repository at this point in the history
Enable logging in `rustls` and `tracing`-using dependencies
  • Loading branch information
ducaale authored Dec 1, 2024
2 parents 05fd88c + e947ca7 commit 0116e82
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
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
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::"));
}

0 comments on commit 0116e82

Please sign in to comment.