Forum Discussion

Patrik_Jonsson's avatar
Nov 19, 2013

Throttle incoming requests per minute

Hi Guys! Trying to write an iRule that throttles incoming requests but I can't get this very simple example to work. Basically my problem seems to be that the global connections variable never is being reset.

Also, I'm not sure if I have to use a global variable in this case. The limit should only affect one particular VIP and the iRule is only used at this VIP.

Throttle number of requests per minute
when RULE_INIT {
    array set connections { }
        after 60000 -periodic {
            array set ::connections { }
        }
    }

when HTTP_REQUEST {
    if { [info exists ::connections([IP::client_addr])] } {
        if { [incr ::connections([IP::client_addr])] > 10 } {
            HTTP::respond 200 content "You have passed the request threshold of 10/minute."
            set blocked 1
        } 
    } else {
        set ::connections([IP::client_addr]) 1
        HTTP::respond 200 content "OK"
    }
}

Thankful for any advice!

Kind regards, Patrik

4 Replies

No RepliesBe the first to reply