Skip to content

Commit

Permalink
Merge pull request #5 from moul/dev/moul/reliable-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Jun 25, 2021
2 parents 60aeb17 + 0d8ad52 commit 44d791b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions chizap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@ func New(logger *zap.Logger, opts *Opts) func(next http.Handler) http.Handler {
zap.Int("size", ww.BytesWritten()),
)
if opts.WithReferer {
reqLogger = reqLogger.With(
zap.String("ref", ww.Header().Get("Referer")),
)
ref := ww.Header().Get("Referer")
if ref == "" {
ref = r.Header.Get("Referer")
}
if ref != "" {
reqLogger = reqLogger.With(zap.String("ref", ref))
}
}
if opts.WithUserAgent {
reqLogger = reqLogger.With(
zap.String("ua", ww.Header().Get("User-Agent")),
)
ua := ww.Header().Get("User-Agent")
if ua == "" {
ua = r.Header.Get("User-Agent")
}
if ua != "" {
reqLogger = reqLogger.With(zap.String("ua", ua))
}
}
reqLogger.Info("Served")
}()
Expand Down

0 comments on commit 44d791b

Please sign in to comment.