From 14908ad3f08993fd370ee1d6d406f97fe8c5a9e0 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 13 Jan 2020 12:24:38 -0800 Subject: [PATCH] Improve debug logging (#781) --- src/async_impl/client.rs | 6 ++++-- src/async_impl/response.rs | 2 -- src/connect.rs | 6 +++--- src/proxy.rs | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index b9cbee6..231953e 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -1189,13 +1189,13 @@ impl Future for PendingRequest { match action { redirect::ActionKind::Follow => { + debug!("redirecting '{}' to '{}'", self.url, loc); self.url = loc; let mut headers = std::mem::replace(self.as_mut().headers(), HeaderMap::new()); remove_sensitive_headers(&mut headers, &self.url, &self.urls); - debug!("redirecting to {:?} '{}'", self.method, self.url); let uri = expect_uri(&self.url); let body = match self.body { Some(Some(ref body)) => Body::reusable(body.clone()), @@ -1224,7 +1224,7 @@ impl Future for PendingRequest { continue; } redirect::ActionKind::Stop => { - debug!("redirect_policy disallowed redirection to '{}'", loc); + debug!("redirect policy disallowed redirection to '{}'", loc); } redirect::ActionKind::Error(err) => { 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()); return Poll::Ready(Ok(res)); } diff --git a/src/async_impl/response.rs b/src/async_impl/response.rs index 17d05c0..c852110 100644 --- a/src/async_impl/response.rs +++ b/src/async_impl/response.rs @@ -9,7 +9,6 @@ use http; use hyper::client::connect::HttpInfo; use hyper::header::CONTENT_LENGTH; use hyper::{HeaderMap, StatusCode, Version}; -use log::debug; use mime::Mime; #[cfg(feature = "json")] use serde::de::DeserializeOwned; @@ -50,7 +49,6 @@ impl Response { let mut headers = parts.headers; let decoder = Decoder::detect(&mut headers, Body::response(body, timeout), gzip); - debug!("Response: '{}' for {}", status, url); Response { status, headers, diff --git a/src/connect.rs b/src/connect.rs index 378f2d4..3db6a16 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -293,7 +293,7 @@ impl Connector { dst: Uri, proxy_scheme: ProxyScheme, ) -> Result { - log::trace!("proxy({:?}) intercepts {:?}", proxy_scheme, dst); + log::debug!("proxy({:?}) intercepts '{:?}'", proxy_scheme, dst); let (proxy_dst, _auth) = match proxy_scheme { ProxyScheme::Http { host, auth } => (into_uri(Scheme::HTTP, host), auth), @@ -421,8 +421,7 @@ where } } -impl Service for Connector -{ +impl Service for Connector { type Response = Conn; type Error = BoxError; type Future = Connecting; @@ -432,6 +431,7 @@ impl Service for Connector } fn call(&mut self, dst: Uri) -> Self::Future { + log::debug!("starting new connection: {:?}", dst); let timeout = self.timeout; for prox in self.proxies.iter() { if let Some(proxy_scheme) = prox.intercept(&dst) { diff --git a/src/proxy.rs b/src/proxy.rs index 25eefe2..313fe68 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -55,7 +55,7 @@ pub struct Proxy { /// A particular scheme used for proxying requests. /// /// For example, HTTP vs SOCKS5 -#[derive(Clone, Debug)] +#[derive(Clone)] pub enum ProxyScheme { Http { auth: Option, @@ -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; #[derive(Clone, Debug)]