Forum Discussion
Leslie_South_55
Nimbostratus
Sep 05, 2007HTTP connection limit + cookie insert from BigIP
I have been working with the codeshare for HTTP Session Limit on
http://devcentral.f5.com/wiki/default.aspx/iRules/HTTPSessionLimit.html
but I am not having any luck. Does anyone know how t...
hoolio
Cirrostratus
Sep 06, 2007What are you actually seeing happen? Persistence shouldn't have any impact on the rule, as it's not specifying which pool members a request goes to.
Here's a version with added debug:
rule HTTP_session_limit {
when RULE_INIT {
set ::debug 1
set ::total_active_clients 0
set ::max_active_clients 100
log local0. "rule session_limit initialized: total/max: $::total_active_clients/$::max_active_clients"
}
when HTTP_REQUEST {
if {$::debug}{ set uri [HTTP::uri]}
; test cookie presence
if {[HTTP::cookie exists "ClientID"]} {
set need_cookie 0
set client_id [HTTP::cookie "ClientID"]
if {$::debug}{ log local0. "client [IP::client_addr] with cookie $client_id -> $uri, count: $::total_active_clients"}
; if cookie not present & connection limit not reached, set up client_id
} else {
if {$::total_active_clients < $::max_active_clients} {
set need_cookie 1
set client_id [format "%08d" [expr { int(100000000 * rand()) }]]
incr ::total_active_clients
if {$::debug}{ log local0. "client [IP::client_addr] with no cookie, under connection limit -> $uri, count: $::total_active_clients"}
; otherwise redirect
} else {
if {$::debug}{ log local0. "client [IP::client_addr] with no cookie over limit, redirected -> $uri, count: $::total_active_clients"}
HTTP::redirect "http://sorry.domain.com/"
return
}
}
}
when HTTP_RESPONSE {
; insert cookie if needed
if {$need_cookie == 1} {
if {$::debug}{ log local0. "client [IP::client_addr] inserting cookie: $client_id"}
HTTP::cookie insert name "ClientID" value $client_id
}
}
when CLIENT_CLOSED {
; decrement current connection counter for this client_id
if {$::total_active_clients > 0} {
incr ::total_active_clients -1
if {$::debug}{ log local0. "client [IP::client_addr] closing connection with cookie $client_id -> $uri, count: $::total_active_clients"}
}
}
}Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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