rate limit tweaks
the /users/{id} prefix contains most API routes so it's not a good idea to put a single rate limit on *all* of them combined. the rate limiter will now ignore the /users/{id} prefix *if* there's a second {id} parameter in the URL. also, X-RateLimit-Bucket is no longer hashed, so it can be directly decoded by clients to get the actual bucket name. i'm not sure if this will actually be useful, but it's nice to have the option.
This commit is contained in:
parent
02e2b230bf
commit
b47ed7b699
2 changed files with 15 additions and 7 deletions
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -91,12 +90,7 @@ func getReset(w http.ResponseWriter) int64 {
|
|||
}
|
||||
|
||||
func requestBucket(method, template string) string {
|
||||
hasher := sha256.New()
|
||||
_, err := hasher.Write([]byte(method + "-" + template))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
return hex.EncodeToString([]byte(method + "-" + template))
|
||||
}
|
||||
|
||||
func (l *Limiter) globalLimiter(user string) *httprate.RateLimiter {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue