Skip to content

Commit

Permalink
feat: run filters earlier to prevent unnecessary processing and fix #40
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Jan 3, 2025
1 parent bb8f9b8 commit b1dc1da
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func NewWithConfig(logger *slog.Logger, config Config) fiber.Handler {
}
}

// Pass thru filters and skip early the code below, to prevent unnecessary processing.
for _, filter := range config.Filters {
if !filter(c) {
return err
}
}

status := c.Response().StatusCode()
method := c.Context().Method()
host := c.Hostname()
Expand Down Expand Up @@ -255,12 +262,6 @@ func NewWithConfig(logger *slog.Logger, config Config) fiber.Handler {
}
}

for _, filter := range config.Filters {
if !filter(c) {
return err
}
}

logErr := err
if logErr == nil {
logErr = fiber.NewError(status)
Expand Down

0 comments on commit b1dc1da

Please sign in to comment.