Skip to content

Update debug middleware #3440

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

Merged
merged 2 commits into from
Mar 21, 2021
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
7 changes: 2 additions & 5 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ pub fn build_middleware(app: Arc<App>, endpoints: RouteBuilder) -> MiddlewareBui
}

if env == Env::Development {
// Print a log for each request.
// Optionally print debug information for each request
// To enable, set the environment variable: `RUST_LOG=cargo_registry::middleware=debug`
m.add(Debug);
}

if env::var_os("DEBUG_REQUESTS").is_some() {
m.add(DebugRequest);
}

if env::var_os("LOG_CONNECTION_POOL_STATUS").is_some() {
m.add(LogConnectionPoolStatus::new(&app));
}
Expand Down
22 changes: 11 additions & 11 deletions src/middleware/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ impl Middleware for Debug {

fn after(&self, _req: &mut dyn RequestExt, res: AfterResult) -> AfterResult {
res.map(|res| {
println!(" <- {:?}", res.status());
debug!(" <- {:?}", res.status());
for (k, v) in res.headers().iter() {
println!(" <- {} {:?}", k, v);
debug!(" <- {} {:?}", k, v);
}
res
})
}
}

#[derive(Clone, Copy, Debug)]
pub struct DebugRequest;
struct DebugRequest;

impl Middleware for DebugRequest {
fn before(&self, req: &mut dyn RequestExt) -> BeforeResult {
println!(" version: {:?}", req.http_version());
println!(" method: {:?}", req.method());
println!(" scheme: {:?}", req.scheme());
println!(" host: {:?}", req.host());
println!(" path: {}", req.path());
println!(" query_string: {:?}", req.query_string());
println!(" remote_addr: {:?}", req.remote_addr());
debug!(" version: {:?}", req.http_version());
debug!(" method: {:?}", req.method());
debug!(" scheme: {:?}", req.scheme());
debug!(" host: {:?}", req.host());
debug!(" path: {}", req.path());
debug!(" query_string: {:?}", req.query_string());
debug!(" remote_addr: {:?}", req.remote_addr());
for (k, ref v) in req.headers().iter() {
println!(" hdr: {}={:?}", k, v);
debug!(" hdr: {}={:?}", k, v);
}
Ok(())
}
Expand Down