In a quite recent discussion on this platform the user wants to count succesful requests, instead of all requests done. I am facing with the same issues, I have found a solution but I don’t see why a very common use case has to be resolved in such specialistic way.
The following, for sake of simplicity, is a common pattern to rate limit incomming requests. The problem with this is, that if a client keeps making requests, it will never expire. The denied requests are tracked as well.
frontend http
stick-table type binary size 100k expire 1m store http_req_rate(1m)
http-request track-sc0 base32+src if { path_end -i .zip } { method GET }
http-request deny deny_status 429 if { path_end -i .zip } { method GET } { sc_http_req_rate(0) gt 2 }
default_backend static
My goal would be to allow a user to make some (succesfull) requests wait a minute, and directly after this wait period have them access the resource again.
backend other
stick-table type binary size 100k expire 1m store gpc0_rate(1m)
http-response sc-inc-gpc0(0) if { status 200 } { method GET }
mode http
server static 127.0.0.1:8000
frontend http
http-request track-sc0 base32+src table other { path_end -i .zip } { method GET }
http-request deny deny_status 429 if { path_end -i .zip } { method GET } { sc0_gpc0_rate gt 2 }
use_backend other if { path_end -i .zip } { method GET }
default_backend static
Am I missing something, and can the first variant with sc_http_req_rate be change not to count the denied request?