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 c18c0f7 commit 8367931
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 @@ -192,12 +192,16 @@ func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc {

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

for k, v := range c.Request().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))
}

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

if config.WithUserAgent {
Expand All @@ -220,12 +224,16 @@ func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc {

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

for k, v := range c.Response().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 8367931

Please sign in to comment.