____177053
Sep 20, 2017Cirrus
Solved
How to limit http request rate
I wants to limit http request rate for some of URIs such as "/a" "/b" "/c",and I wrote one but it didn't work:
when HTTP_REQUEST { set start_time [clock seconds] set reqs_sec 0 if { [HTTP::request_num] > 3 } { log local0. "num:[HTTP::request_num]" if { [clock seconds] == $start_time } { log local0. "time:$start_time" if { $reqs_sec > 3 } { reject log local0. "reject from [IP::client_addr]" } incr reqs_sec return } } }
How to modify this one and make it limit 3-times http requests in 3 seconds?
Thanks a lot!
This one works! when HTTP_REQUEST {
set lrqst 10 set ltime 10 set rtime 5 if {[table lookup -notouch -subtable "blacklist" [HTTP::uri]] != "" }{ reject log local0.warn "reject" } elseif { [table lookup -notouch -subtable "clientxdlist" [HTTP::uri]] == "" }{ table set -subtable "clientxdlist" [HTTP::uri] 1 indefinite $ltime } elseif { [table lookup -notouch -subtable "clientxdlist" [HTTP::uri]] < $lrqst}{ table incr -subtable "clientxdlist" [HTTP::uri] } else { table set -subtable "blacklist" [HTTP::uri] 1 indefinite $rtime }
}