Skip to content

Commit cad7314

Browse files
committed
Debug incoming requests
1 parent 3d22698 commit cad7314

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
120120
}
121121

122122
let mut m = MiddlewareBuilder::new(R404(router));
123+
m.add(DebugMiddleware);
123124
if env != Env::Test {
124125
m.add(conduit_log_requests::LogRequests(0));
125126
}
@@ -136,6 +137,35 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
136137
}
137138

138139
return m;
140+
141+
struct DebugMiddleware;
142+
143+
impl conduit_middleware::Middleware for DebugMiddleware {
144+
fn before(&self, req: &mut conduit::Request)
145+
-> Result<(), Box<std::fmt::Show + 'static>> {
146+
println!("version: {}", req.http_version());
147+
println!("method: {}", req.method());
148+
println!("scheme: {}", req.scheme());
149+
println!("host: {}", req.host());
150+
println!("path: {}", req.path());
151+
println!("query_string: {}", req.query_string());
152+
for &(k, ref v) in req.headers().all().iter() {
153+
println!("hdr: {}={}", k, v);
154+
}
155+
Ok(())
156+
}
157+
fn after(&self, req: &mut conduit::Request,
158+
res: Result<conduit::Response, Box<std::fmt::Show + 'static>>)
159+
-> Result<conduit::Response, Box<std::fmt::Show + 'static>> {
160+
res.map(|res| {
161+
println!("<- {}", res.status);
162+
for (k, v) in res.headers.iter() {
163+
println!("<- {} {}", k, v);
164+
}
165+
res
166+
})
167+
}
168+
}
139169
}
140170

141171
pub fn now() -> time::Timespec {

0 commit comments

Comments
 (0)