@@ -120,6 +120,7 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
120
120
}
121
121
122
122
let mut m = MiddlewareBuilder :: new ( R404 ( router) ) ;
123
+ m. add ( DebugMiddleware ) ;
123
124
if env != Env :: Test {
124
125
m. add ( conduit_log_requests:: LogRequests ( 0 ) ) ;
125
126
}
@@ -136,6 +137,35 @@ pub fn middleware(app: Arc<App>) -> MiddlewareBuilder {
136
137
}
137
138
138
139
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
+ }
139
169
}
140
170
141
171
pub fn now ( ) -> time:: Timespec {
0 commit comments