Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Didip Kerabat committed Oct 9, 2024
1 parent 4746e5e commit 5a782cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
// Create a request limiter per handler.
lmt := tollbooth.NewLimiter(1, nil)

// New in version >= 7, you must explicitly define how to pick the IP address.
// New in version >= 8, you must explicitly define how to pick the IP address.
lmt.SetIPLookup(limiter.IPLookup{
Name: "X-Real-IP",
IndexFromRight: 0,
Expand Down Expand Up @@ -78,7 +78,7 @@ func main() {
// every token bucket in it will expire 1 hour after it was initially set.
lmt = tollbooth.NewLimiter(1, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Hour})

// New in version >= 7, you must explicitly define how to pick the IP address.
// New in version >= 8, you must explicitly define how to pick the IP address.
// If IP address cannot be found, rate limiter will not be activated.
lmt.SetIPLookup(limiter.IPLookup{
// The name of lookup method.
Expand All @@ -95,7 +95,7 @@ func main() {
IndexFromRight: 0,
})

// In version >= 7, lmt.SetIPLookups and lmt.GetIPLookups are removed.
// In version >= 8, lmt.SetIPLookups and lmt.GetIPLookups are removed.

// Limit only GET and POST requests.
lmt.SetMethods([]string{"GET", "POST"})
Expand Down Expand Up @@ -162,7 +162,7 @@ func main() {
```go
lmt := tollbooth.NewLimiter(1, nil)
// New in version >= 7, you must explicitly define how to pick the IP address.
// New in version >= 8, you must explicitly define how to pick the IP address.
lmt.SetIPLookup(limiter.IPLookup{
Name: "X-Forwarded-For",
IndexFromRight: 0,
Expand Down
2 changes: 1 addition & 1 deletion libstring/libstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"strings"

"github.com/didip/tollbooth/v6/limiter"
"github.com/didip/tollbooth/v7/limiter"
)

// StringInSlice finds needle in a slice of strings.
Expand Down
5 changes: 4 additions & 1 deletion tollbooth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,10 @@ func (lm *LockMap) Add(key string, incr int64) {

func TestLimitHandlerEmptyHeader(t *testing.T) {
lmt := limiter.New(nil).SetMax(1).SetBurst(1)
lmt.SetIPLookups([]string{"X-Real-IP", "RemoteAddr", "X-Forwarded-For"})
lmt.SetIPLookup(limiter.IPLookup{
Name: "X-Real-IP",
IndexFromRight: 0,
})
lmt.SetMethods([]string{"POST"})
lmt.SetHeader("user_id", []string{})

Expand Down

0 comments on commit 5a782cc

Please sign in to comment.