Skip to content

Commit

Permalink
fix: dedup "headers" attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Feb 12, 2024
1 parent 69ec7fd commit 2140508
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ func NewWithConfig(logger *slog.Logger, config Config) func(http.Handler) http.H

// request headers
if config.WithRequestHeader {
kv := []any{}

for k, v := range r.Header {
if _, found := HiddenRequestHeaders[strings.ToLower(k)]; found {
continue
}
requestAttributes = append(requestAttributes, slog.Group("header", slog.Any(k, v)))
kv = append(kv, slog.Any(k, v))
}

requestAttributes = append(requestAttributes, slog.Group("header", kv...))
}

if config.WithUserAgent {
Expand All @@ -195,12 +199,16 @@ func NewWithConfig(logger *slog.Logger, config Config) func(http.Handler) http.H

// response headers
if config.WithResponseHeader {
kv := []any{}

for k, v := range w.Header() {
if _, found := HiddenResponseHeaders[strings.ToLower(k)]; found {
continue
}
responseAttributes = append(responseAttributes, slog.Group("header", slog.Any(k, v)))
kv = append(kv, slog.Any(k, v))
}

responseAttributes = append(responseAttributes, slog.Group("header", kv...))
}

attributes := append(
Expand Down

0 comments on commit 2140508

Please sign in to comment.