RefererHandler adds the request's referer as a field to the context's logger using fieldKey as field key.
(fieldKey string)
| 139 | // RefererHandler adds the request's referer as a field to the context's logger |
| 140 | // using fieldKey as field key. |
| 141 | func 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. |