Skip to content

Commit 9feb7ab

Browse files
committed
Enable logging in rustls and tracing-using dependencies
Enable `rustls`'s `logging` feature to start emitting logs. Enable the `tracing` crate's `log` feature to hook up the dependencies that log via that crate. `hyper` can use `tracing` but it's currently unstable and locked behind `RUSTFLAGS='--cfg hyper_unstable_tracing'` so we shouldn't use it yet. This partially addresses ducaale#389. ```console $ RUST_LOG=trace/ALPN xh https://example.org [0.495665s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2") [0.499526s TRACE hyper_util::client::legacy::client] ALPN negotiated h2, updating pool HTTP/2.0 200 OK [...] $ RUST_LOG=rustls xh https://example.org [0.288085s DEBUG rustls::client::hs] No cached session for DnsName("example.org") [0.288657s DEBUG rustls::client::hs] Not resuming any session [0.288767s TRACE rustls::client::hs] Sending ClientHello Message { version: TLSv1_0, payload: Handshake { [...] [0.698465s DEBUG rustls::client::hs] Using ciphersuite TLS13_AES_256_GCM_SHA384 [0.698508s DEBUG rustls::client::tls13] Not resuming [0.698530s TRACE rustls::client::client_conn] EarlyData rejected [0.699267s DEBUG rustls::client::tls13] TLS1.3 encrypted extensions: [Protocols([ProtocolName(6832)])] [0.699342s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2") [0.699578s TRACE rustls::client::tls13] Server cert is CertificateChain([CertificateDer(0x3082076e3082[...] ``` `native-tls` barely has any logging so we don't get much useful info from there yet.
1 parent 05fd88c commit 9feb7ab

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

Cargo.lock

+8-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dirs = "5.0"
2626
encoding_rs = "0.8.28"
2727
encoding_rs_io = "0.1.7"
2828
flate2 = "1.0.22"
29+
# Add "tracing" feature to hyper once it stabilizes
2930
hyper = { version = "1.2", default-features = false }
3031
indicatif = "0.17"
3132
jsonxf = "1.1.0"
@@ -52,6 +53,11 @@ ruzstd = { version = "0.7", default-features = false, features = ["std"]}
5253
env_logger = { version = "0.11.3", default-features = false, features = ["color", "auto-color", "humantime"] }
5354
log = "0.4.21"
5455

56+
# Enable logging in transitive dependencies.
57+
# The rustls version number should be kept in sync with hyper/reqwest.
58+
rustls = { version = "0.23.14", optional = true, default-features = false, features = ["logging"] }
59+
tracing = { version = "0.1.41", default-features = false, features = ["log"] }
60+
5561
[dependencies.reqwest]
5662
version = "0.12.3"
5763
default-features = false
@@ -85,7 +91,7 @@ http-body-util = "0.1.1"
8591
[features]
8692
default = ["online-tests", "rustls", "network-interface"]
8793
native-tls = ["reqwest/native-tls", "reqwest/native-tls-alpn"]
88-
rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-webpki-roots", "reqwest/rustls-tls-native-roots"]
94+
rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-webpki-roots", "reqwest/rustls-tls-native-roots", "dep:rustls"]
8995

9096
# To be used by platforms that don't support binding to interface via SO_BINDTODEVICE
9197
# Ideally, this would be auto-disabled on platforms that don't need it

tests/cases/logging.rs

+20
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,23 @@ fn warning_for_non_utf8_redirect() {
124124
.assert()
125125
.stderr("xh: warning: Redirect to invalid URL: \"\\xff\"\n");
126126
}
127+
128+
/// This test should fail if rustls's version gets out of sync in Cargo.toml.
129+
#[cfg(feature = "rustls")]
130+
#[test]
131+
fn rustls_emits_logs() {
132+
let mut server = server::http(|_req| async move {
133+
unreachable!();
134+
});
135+
server.disable_hit_checks();
136+
let cmd = get_command()
137+
.arg("--debug")
138+
.arg(&server.base_url().replace("http://", "https://"))
139+
.env_remove("RUST_LOG")
140+
.assert()
141+
.failure();
142+
143+
assert!(std::str::from_utf8(&cmd.get_output().stderr)
144+
.unwrap()
145+
.contains("rustls::"));
146+
}

0 commit comments

Comments
 (0)