Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic retryafter #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"net/http"
"time"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httprate"
"github.com/Alge/chi/v5"
"github.com/Alge/chi/v5/middleware"
"github.com/Alge/httprate"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/go-chi/httprate
module github.com/Alge/httprate

go 1.17

Expand Down
4 changes: 3 additions & 1 deletion limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func (l *RateLimiter) OnLimit(w http.ResponseWriter, r *http.Request, key string
setHeader(w, l.headers.Remaining, fmt.Sprintf("%d", limit-rate))

l.mu.Unlock()
setHeader(w, l.headers.RetryAfter, fmt.Sprintf("%d", int(l.windowLength.Seconds()))) // RFC 6585

retryAfter := int(math.Ceil(time.Now().UTC().Sub(currentWindow.Add(l.windowLength)).Seconds()))
setHeader(w, l.headers.RetryAfter, fmt.Sprintf("%d", retryAfter)) // RFC 6585
return true
}

Expand Down
2 changes: 1 addition & 1 deletion limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"time"

"github.com/go-chi/httprate"
"github.com/Alge/httprate"
)

func TestLimit(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion local_counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/go-chi/httprate"
"github.com/Alge/httprate"
"golang.org/x/sync/errgroup"
)

Expand Down