AccessHandler returns a handler that call f after each request.
(f func(r *http.Request, status, size int, duration time.Duration))
| 290 | |
| 291 | // AccessHandler returns a handler that call f after each request. |
| 292 | func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler { |
| 293 | return func(next http.Handler) http.Handler { |
| 294 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 295 | start := time.Now() |
| 296 | lw := mutil.WrapWriter(w) |
| 297 | defer func() { |
| 298 | f(r, lw.Status(), lw.BytesWritten(), time.Since(start)) |
| 299 | }() |
| 300 | next.ServeHTTP(lw, r) |
| 301 | }) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | // HostHandler adds the request's host as a field to the context's logger |
| 306 | // using fieldKey as field key. If trimPort is set to true, then port is |
nothing calls this directly
no test coverage detected