MCPcopy
hub / github.com/rs/zerolog / ResponseHeaderHandler

Function ResponseHeaderHandler

hlog/hlog.go:274–289  ·  view source on GitHub ↗
(fieldKey, headerName string)

Source from the content-addressed store, hash-verified

272}
273
274func ResponseHeaderHandler(fieldKey, headerName string) func(next http.Handler) http.Handler {
275 return func(next http.Handler) http.Handler {
276 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
277 defer func() {
278 value := w.Header().Get(headerName)
279 if value != "" {
280 log := zerolog.Ctx(r.Context())
281 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
282 return c.Str(fieldKey, value)
283 })
284 }
285 }()
286 next.ServeHTTP(w, r)
287 })
288 }
289}
290
291// AccessHandler returns a handler that call f after each request.
292func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler {

Callers 1

Calls 3

CtxFunction · 0.92
UpdateContextMethod · 0.80
StrMethod · 0.45

Tested by 1