Skip to content

Commit

Permalink
Fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Iles committed Jun 8, 2018
1 parent e193089 commit c51e593
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,21 @@ func validateContract(next http.HandlerFunc) http.HandlerFunc {
// validateMaxTransactions checks that the number of transactions in the request does not exceed the defined maximum.
func validateMaxTransactions(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {

transactions, ctx, err := getTransactions(r)

if err != nil {
logFailure(err.Error(), w, r, 0)
return
}

if len(transactions) > appConfig.MaxTransactions {
logFailure("TOO_MANY_TRANSACTIONS", w, r, 0)
return
// Skip this middleware if MaxTransactions is not configured, or set to 0
if appConfig.MaxTransactions > 0 {
if len(transactions) > appConfig.MaxTransactions {
logFailure("TOO_MANY_TRANSACTIONS", w, r, 0)
return
}
}

next.ServeHTTP(w, r.WithContext(ctx))
}
}
Expand Down

0 comments on commit c51e593

Please sign in to comment.