Improve debug logging (#781)

This commit is contained in:
Sean McArthur
2020-01-13 12:24:38 -08:00
committed by GitHub
parent 1478313756
commit 14908ad3f0
4 changed files with 40 additions and 8 deletions

View File

@@ -1189,13 +1189,13 @@ impl Future for PendingRequest {
match action { match action {
redirect::ActionKind::Follow => { redirect::ActionKind::Follow => {
debug!("redirecting '{}' to '{}'", self.url, loc);
self.url = loc; self.url = loc;
let mut headers = let mut headers =
std::mem::replace(self.as_mut().headers(), HeaderMap::new()); std::mem::replace(self.as_mut().headers(), HeaderMap::new());
remove_sensitive_headers(&mut headers, &self.url, &self.urls); remove_sensitive_headers(&mut headers, &self.url, &self.urls);
debug!("redirecting to {:?} '{}'", self.method, self.url);
let uri = expect_uri(&self.url); let uri = expect_uri(&self.url);
let body = match self.body { let body = match self.body {
Some(Some(ref body)) => Body::reusable(body.clone()), Some(Some(ref body)) => Body::reusable(body.clone()),
@@ -1224,7 +1224,7 @@ impl Future for PendingRequest {
continue; continue;
} }
redirect::ActionKind::Stop => { redirect::ActionKind::Stop => {
debug!("redirect_policy disallowed redirection to '{}'", loc); debug!("redirect policy disallowed redirection to '{}'", loc);
} }
redirect::ActionKind::Error(err) => { redirect::ActionKind::Error(err) => {
return Poll::Ready(Err(crate::error::redirect( return Poll::Ready(Err(crate::error::redirect(
@@ -1235,6 +1235,8 @@ impl Future for PendingRequest {
} }
} }
} }
debug!("response '{}' for {}", res.status(), self.url);
let res = Response::new(res, self.url.clone(), self.client.gzip, self.timeout.take()); let res = Response::new(res, self.url.clone(), self.client.gzip, self.timeout.take());
return Poll::Ready(Ok(res)); return Poll::Ready(Ok(res));
} }

View File

@@ -9,7 +9,6 @@ use http;
use hyper::client::connect::HttpInfo; use hyper::client::connect::HttpInfo;
use hyper::header::CONTENT_LENGTH; use hyper::header::CONTENT_LENGTH;
use hyper::{HeaderMap, StatusCode, Version}; use hyper::{HeaderMap, StatusCode, Version};
use log::debug;
use mime::Mime; use mime::Mime;
#[cfg(feature = "json")] #[cfg(feature = "json")]
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
@@ -50,7 +49,6 @@ impl Response {
let mut headers = parts.headers; let mut headers = parts.headers;
let decoder = Decoder::detect(&mut headers, Body::response(body, timeout), gzip); let decoder = Decoder::detect(&mut headers, Body::response(body, timeout), gzip);
debug!("Response: '{}' for {}", status, url);
Response { Response {
status, status,
headers, headers,

View File

@@ -293,7 +293,7 @@ impl Connector {
dst: Uri, dst: Uri,
proxy_scheme: ProxyScheme, proxy_scheme: ProxyScheme,
) -> Result<Conn, BoxError> { ) -> Result<Conn, BoxError> {
log::trace!("proxy({:?}) intercepts {:?}", proxy_scheme, dst); log::debug!("proxy({:?}) intercepts '{:?}'", proxy_scheme, dst);
let (proxy_dst, _auth) = match proxy_scheme { let (proxy_dst, _auth) = match proxy_scheme {
ProxyScheme::Http { host, auth } => (into_uri(Scheme::HTTP, host), auth), ProxyScheme::Http { host, auth } => (into_uri(Scheme::HTTP, host), auth),
@@ -421,8 +421,7 @@ where
} }
} }
impl Service<Uri> for Connector impl Service<Uri> for Connector {
{
type Response = Conn; type Response = Conn;
type Error = BoxError; type Error = BoxError;
type Future = Connecting; type Future = Connecting;
@@ -432,6 +431,7 @@ impl Service<Uri> for Connector
} }
fn call(&mut self, dst: Uri) -> Self::Future { fn call(&mut self, dst: Uri) -> Self::Future {
log::debug!("starting new connection: {:?}", dst);
let timeout = self.timeout; let timeout = self.timeout;
for prox in self.proxies.iter() { for prox in self.proxies.iter() {
if let Some(proxy_scheme) = prox.intercept(&dst) { if let Some(proxy_scheme) = prox.intercept(&dst) {

View File

@@ -55,7 +55,7 @@ pub struct Proxy {
/// A particular scheme used for proxying requests. /// A particular scheme used for proxying requests.
/// ///
/// For example, HTTP vs SOCKS5 /// For example, HTTP vs SOCKS5
#[derive(Clone, Debug)] #[derive(Clone)]
pub enum ProxyScheme { pub enum ProxyScheme {
Http { Http {
auth: Option<HeaderValue>, auth: Option<HeaderValue>,
@@ -434,6 +434,38 @@ impl ProxyScheme {
} }
} }
impl fmt::Debug for ProxyScheme {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ProxyScheme::Http {
auth: _auth,
host,
} => {
write!(f, "http://{}", host)
},
ProxyScheme::Https {
auth: _auth,
host,
} => {
write!(f, "https://{}", host)
},
#[cfg(feature = "socks")]
ProxyScheme::Socks5 {
addr,
auth: _auth,
remote_dns,
} => {
let h = if *remote_dns {
"h"
} else {
""
};
write!(f, "socks5{}://{}", h, addr)
}
}
}
}
type SystemProxyMap = HashMap<String, ProxyScheme>; type SystemProxyMap = HashMap<String, ProxyScheme>;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]