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

Function RefererHandler

hlog/hlog.go:141–153  ·  view source on GitHub ↗

RefererHandler adds the request's referer as a field to the context's logger using fieldKey as field key.

(fieldKey string)

Source from the content-addressed store, hash-verified

139// RefererHandler adds the request's referer as a field to the context's logger
140// using fieldKey as field key.
141func RefererHandler(fieldKey string) func(next http.Handler) http.Handler {
142 return func(next http.Handler) http.Handler {
143 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
144 if ref := r.Header.Get("Referer"); ref != "" {
145 log := zerolog.Ctx(r.Context())
146 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
147 return c.Str(fieldKey, ref)
148 })
149 }
150 next.ServeHTTP(w, r)
151 })
152 }
153}
154
155// ProtoHandler adds the requests protocol version as a field to the context logger
156// using fieldKey as field Key.

Callers 2

Example_handlerFunction · 0.92
TestRefererHandlerFunction · 0.85

Calls 3

CtxFunction · 0.92
UpdateContextMethod · 0.80
StrMethod · 0.45

Tested by 2

Example_handlerFunction · 0.74
TestRefererHandlerFunction · 0.68