Skip to content

Commit

Permalink
Merge pull request TykTechnologies#49 from weters/master
Browse files Browse the repository at this point in the history
TykTechnologies#48: Fix off-by-one error with rate limiting
  • Loading branch information
lonelycode committed Mar 13, 2015
2 parents ec7ec06 + 4e341e7 commit 8af69bd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ func TestThrottling(t *testing.T) {
secondRecorder := httptest.NewRecorder()
chain.ServeHTTP(secondRecorder, req)

if secondRecorder.Code != 200 {
t.Error("Second request failed with non-200 code: \n", secondRecorder.Code)
}

thirdRecorder := httptest.NewRecorder()
chain.ServeHTTP(thirdRecorder, req)

Expand Down
2 changes: 1 addition & 1 deletion session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (l SessionLimiter) ForwardMessage(currentSession *SessionState, key string,
rateLimiterKey := RateLimitKeyPrefix + key
ratePerPeriodNow := store.IncrememntWithExpire(rateLimiterKey, int64(currentSession.Per))

if ratePerPeriodNow >= (int64(currentSession.Rate)) {
if ratePerPeriodNow > (int64(currentSession.Rate)) {
return false, 1
}

Expand Down

0 comments on commit 8af69bd

Please sign in to comment.