Forum Discussion
Heegun_83188
Jun 02, 2010Historic F5 Account
Seek opinion on an iRule code block --- HTTP Request Throttling
Hi all,
Please can someone help analyze the below code block? I wonder if there is a mistake in it, but need your help to confirm it. Thanks in advance.
REQUIREMENT:
Limit the client to make up to 3 requests every 3 seconds. If it's exceeded, then iRule forces the browser to delay 2 seconds before trying again.
CODE:
when HTTP_REQUEST {
set cur_time [clock seconds]
if { [HTTP::request_num] > 3 } {
if { $cur_time == $start_time } {
if { $reqs_sec > 3 } {
HTTP::respond 503 Retry-After 2
}
incr reqs_sec
return
}
}
set start_time $cur_time
set reqs_sec 0
}
CONCERNS:
Say if a client makes requests as follows:
Sec 1: Req 1
Sec 2: Req 2
Sec 3: Req 3 and Req 4
According to requirement, it should be delayed at sec 3 with a 503 status code. However,code going through:
Req 1: $start_time = $cur_time; $reqs_sec = 0
Req 2: $start_time = $cur_time; $reqs_sec = 0
Req 3: $start_time = $cur_time; $reqs_sec = 0
Req 4: $start_time = $cur_time; $HTTP:request_num = 4; reqs_sec = 1;
The delay action is NOT performed.
QUESTIONS:
If situation like the above happens, the code block won't perform as required. Am I correct?
Regards,
Sen
1 Reply
- The_Bhattman
Nimbostratus
H Sen,
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects