Skip to content

Commit

Permalink
Add an option to overwrite which IP the rate-limiter chooses
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Jun 30, 2023
1 parent 9f03a9b commit e812700
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ type ConfigAuth struct {
}

type ConfigRateLimit struct {
Rate float64 `json:"rate" validate:"required"`
Burst int `json:"burst" validate:"required"`
TTL int `json:"ttl" validate:"required"`
Reason string `json:"reason"`
Rate float64 `json:"rate" validate:"required"`
Burst int `json:"burst" validate:"required"`
TTL int `json:"ttl" validate:"required"`
IpLookupHeader string `json:"ipheader"`
Reason string `json:"reason"`
}

type ConfigWorker struct {
Expand Down
3 changes: 3 additions & 0 deletions backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ func server(jobsystem JobSystem, config ConfigRoot) {
SetBurst(config.Server.RateLimit.Burst).
SetMessageContentType("application/json; charset=utf-8").
SetMessage(string(b))
if config.Server.RateLimit.IpLookupHeader == "" {
lmt.SetIPLookups([]string{config.Server.RateLimit.IpLookupHeader})
}
if config.App == AppMMseqs2 || config.App == AppFoldSeek {
r.Handle("/ticket", tollbooth.LimitFuncHandler(lmt, ticketHandlerFunc)).Methods("POST")
}
Expand Down

0 comments on commit e812700

Please sign in to comment.