Forum Discussion
admin_xk_99638
Mar 13, 2012Nimbostratus
when RULE_INIT {
; set ::total_active_clients 0
; set ::max_active_clients 3000
set ::holding_page_be "http://www.testing.com"
set ::debug_mode 0
log local0. "rule session_limit initialized: total/max/debug_mode: $::total_active_clients/$::max_active_clients/$::debug_mode"
}
when HTTP_REQUEST {
; test cookie presence
if {[HTTP::uri] contains "maxLimit.do"} {
if {[HTTP::cookie value "SeatOfferPage"] == "successful"} {
log local0. "TE kick out user after step 1!"
}
}
if {[HTTP::cookie exists "TM2003218"]} {
set need_cookie 0
set client_id [HTTP::cookie "TM2003218"]
; if cookie not present & connection limit not reached, set up client_id
;log local0. "old client id $client_id, current number $::total_active_clients"
if {$::debug_mode >= 4} {log local0. "Returning customer with cookie value: $client_id"}
} else {
if {$::total_active_clients < $::max_active_clients} {
if {[HTTP::uri] contains "SeatAvailability.do"} {
set need_cookie 1
set client_id [format "%08d" [expr { int(100000000 * rand()) }]]
if {$::debug_mode >= 1} {log local0. "1-New customer with cookie value: $client_id, IP:[IP::client_addr], total_active_clients: $::total_active_clients"}
incr ::total_active_clients
; otherwise redirect
;log local0. "new client id $client_id, current number $::total_active_clients"
}
} else {
; set need_cookie 2
if {$::debug_mode >= 2} {log local0. "Excced limit now, total_active_clients: $::total_active_clients"}
HTTP::respond 302 Location $::holding_page_te "Cache-Control" "no-cache" "Pragma" "no-cache"
return
}
}
}
when HTTP_RESPONSE {
; insert cookie if needed
if {$need_cookie == 1} {
HTTP::cookie insert name "magicClientName" value "TM2003218"
HTTP::cookie insert name "TM2003218" value $client_id
}
; if {$need_cookie == 2} {
; HTTP::respond 302 Location $::holding_page_te "Cache-Control" "no-cache" "Pragma" "no-cache"
; return
; }
}
when CLIENT_CLOSED {
; decrement current connection counter for this client_id
if {$::total_active_clients > 0} {
incr ::total_active_clients -1
if {$::debug_mode >= 1} {log local0. "Client dropped, total_active_clients: $::total_active_clients"}
}
}