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

Add convenience debugging for HTTP requests in Cargo #6166

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
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
30 changes: 29 additions & 1 deletion src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::collections::BTreeMap;
use std::fs::{self, File};
use std::iter::repeat;
use std::str;
use std::time::Duration;
use std::{cmp, env};

use curl::easy::{Easy, SslOpt};
use log::Level;
use curl::easy::{Easy, SslOpt, InfoType};
use git2;
use registry::{NewCrate, NewCrateDependency, Registry};

Expand Down Expand Up @@ -388,6 +390,32 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
} else {
handle.useragent(&version().to_string())?;
}

if let Some(true) = config.get::<Option<bool>>("http.debug")? {
handle.verbose(true)?;
handle.debug_function(|kind, data| {
let (prefix, level) = match kind {
InfoType::Text => ("*", Level::Debug),
InfoType::HeaderIn => ("<", Level::Debug),
InfoType::HeaderOut => (">", Level::Debug),
InfoType::DataIn => ("{", Level::Trace),
InfoType::DataOut => ("}", Level::Trace),
InfoType::SslDataIn |
InfoType::SslDataOut => return,
_ => return,
};
match str::from_utf8(data) {
Ok(s) => {
for line in s.lines() {
log!(level, "http-debug: {} {}", prefix, line);
}
}
Err(_) => {
log!(level, "http-debug: {} ({} bytes of data)", prefix, data.len());
}
}
})?;
}
Ok(())
}

Expand Down
10 changes: 10 additions & 0 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ check-revoke = true # Indicates whether SSL certs are checked for revocation
low-speed-limit = 5 # Lower threshold for bytes/sec (10 = default, 0 = disabled)
multiplexing = false # whether or not to use HTTP/2 multiplexing where possible

# This setting can be used to help debug what's going on with HTTP requests made
# by Cargo. When set to `true` then Cargo's normal debug logging will be filled
# in with HTTP information, which you can extract with
# `RUST_LOG=cargo::ops::registry=debug` (and `trace` may print more).
#
# Be wary when posting these logs elsewhere though, it may be the case that a
# header has an authentication token in it you don't want leaked! Be sure to
# briefly review logs before posting them.
debug = false

[build]
jobs = 1 # number of parallel jobs, defaults to # of CPUs
rustc = "rustc" # the rust compiler tool
Expand Down