Skip to content

Commit

Permalink
urgent fix for ratelimits
Browse files Browse the repository at this point in the history
  • Loading branch information
superisaac committed Nov 25, 2024
1 parent bf1e9a6 commit 70e6602
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func AccFromContext(ctx context.Context) *Acc {
panic("context does not have account")
}

func AccFromContextOrNil(ctx context.Context) *Acc {
if v := ctx.Value("account"); v != nil {
if acc, ok := v.(*Acc); ok {
return acc
}
}
return nil
}

type AccHandler struct {
rootCtx context.Context
next http.Handler
Expand Down
6 changes: 5 additions & 1 deletion server/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func NewRatelimitHandler(rootCtx context.Context, next http.Handler) *RatelimitH
}

func (handler *RatelimitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
acc := AccFromContext(r.Context())
acc := AccFromContextOrNil(r.Context())
if acc == nil {
handler.next.ServeHTTP(w, r)
return
}
var ratelimit RatelimitConfig
var accName string
if acc != nil {
Expand Down

0 comments on commit 70e6602

Please sign in to comment.