Forum Discussion

kashanihra's avatar
Icon for Nimbostratus rankNimbostratus
Jun 17, 2024

how set connection rate limit on specific uri with iRule ?


I use this iRule 

when RULE_INIT {
#Allow 3 Requests every 1 Second
set static::maxRate 5
set static::windowSecs 1
   if {[HTTP::host] equals "" and [string tolower [HTTP::uri]] contains "/favicon.ico"}
    elseif {[HTTP::host] equals "" and [string tolower [HTTP::uri]] contains "/openapi/v0/identity/register" } {
    set uri_limitervar [HTTP::uri]
    set get_count [table key -count -subtable $uri_limitervar]
    if { $get_count < $static::maxRate } {
        incr get_count 1
         table set -subtable $uri_limitervar $get_count $uri_limitervar indefinite $static::windowSecs
         } else {

                HTTP::respond 503 content "<html><h2>You have exceeded the maximum number of requests per minute allowed... Try again later.</h2></html>"

                #Drop the Connection afterwards
    elseif {[HTTP::host] equals "" and [string tolower [HTTP::uri]] contains "/openapi" } {
    HTTP::header replace "Host" ""
    HTTP::header insert X-Forwarded-For [IP::remote_addr]
    HTTP::header insert X-Geo-Country-Code [whereis [IP::client_addr] country ]
    HTTP::header insert X-Geo-Country-Area [whereis [IP::client_addr]  state  ]
#   SSL::disable serverside
    pool Prd-NGNX_443

but after 10 or 5 minute all connection for this uri will drop.
and now what is the problem?

No RepliesBe the first to reply