You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-12-07 23:32:55 +02:00
IMGPROXY_REQUESTS_QUEUE_SIZE config
This commit is contained in:
@@ -29,12 +29,17 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
queueSem *semaphore.Semaphore
|
||||
processingSem *semaphore.Semaphore
|
||||
|
||||
headerVaryValue string
|
||||
)
|
||||
|
||||
func initProcessingHandler() {
|
||||
if config.RequestsQueueSize > 0 {
|
||||
queueSem = semaphore.New(config.RequestsQueueSize + config.Concurrency)
|
||||
}
|
||||
|
||||
processingSem = semaphore.New(config.Concurrency)
|
||||
|
||||
vary := make([]string, 0)
|
||||
@@ -176,6 +181,14 @@ func checkErr(ctx context.Context, errType string, err error) {
|
||||
func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
if queueSem != nil {
|
||||
token, aquired := queueSem.TryAquire()
|
||||
if !aquired {
|
||||
panic(ierrors.New(429, "Too many requests", "Too many requests"))
|
||||
}
|
||||
defer token.Release()
|
||||
}
|
||||
|
||||
path := r.RequestURI
|
||||
if queryStart := strings.IndexByte(path, '?'); queryStart >= 0 {
|
||||
path = path[:queryStart]
|
||||
|
||||
Reference in New Issue
Block a user