|
@@ -298,23 +298,25 @@ func debugMiddleware(h http.Handler) http.Handler {
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
t0 := time.Now()
|
|
t0 := time.Now()
|
|
|
h.ServeHTTP(w, r)
|
|
h.ServeHTTP(w, r)
|
|
|
- ms := 1000 * time.Since(t0).Seconds()
|
|
|
|
|
-
|
|
|
|
|
- // The variable `w` is most likely a *http.response, which we can't do
|
|
|
|
|
- // much with since it's a non exported type. We can however peek into
|
|
|
|
|
- // it with reflection to get at the status code and number of bytes
|
|
|
|
|
- // written.
|
|
|
|
|
- var status, written int64
|
|
|
|
|
- if rw := reflect.Indirect(reflect.ValueOf(w)); rw.IsValid() && rw.Kind() == reflect.Struct {
|
|
|
|
|
- if rf := rw.FieldByName("status"); rf.IsValid() && rf.Kind() == reflect.Int {
|
|
|
|
|
- status = rf.Int()
|
|
|
|
|
- }
|
|
|
|
|
- if rf := rw.FieldByName("written"); rf.IsValid() && rf.Kind() == reflect.Int64 {
|
|
|
|
|
- written = rf.Int()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if shouldDebugHTTP() {
|
|
|
|
|
+ ms := 1000 * time.Since(t0).Seconds()
|
|
|
|
|
+
|
|
|
|
|
+ // The variable `w` is most likely a *http.response, which we can't do
|
|
|
|
|
+ // much with since it's a non exported type. We can however peek into
|
|
|
|
|
+ // it with reflection to get at the status code and number of bytes
|
|
|
|
|
+ // written.
|
|
|
|
|
+ var status, written int64
|
|
|
|
|
+ if rw := reflect.Indirect(reflect.ValueOf(w)); rw.IsValid() && rw.Kind() == reflect.Struct {
|
|
|
|
|
+ if rf := rw.FieldByName("status"); rf.IsValid() && rf.Kind() == reflect.Int {
|
|
|
|
|
+ status = rf.Int()
|
|
|
|
|
+ }
|
|
|
|
|
+ if rf := rw.FieldByName("written"); rf.IsValid() && rf.Kind() == reflect.Int64 {
|
|
|
|
|
+ written = rf.Int()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ l.Debugf("http: %s %q: status %d, %d bytes in %.02f ms", r.Method, r.URL.String(), status, written, ms)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- l.Debugf("http: %s %q: status %d, %d bytes in %.02f ms", r.Method, r.URL.String(), status, written, ms)
|
|
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|