dirken
Jun 26, 2014Nimbostratus
howto set cookie and cookie persistence at the same time
My iRule assigns pools according to keywords in the URI. For one special URI and the corresponding pool I want to limit the http connections via table command and cookies. Works more or less in the lab but for the persistence...
How can I assign a cookie persistence in HTTP_REQUEST if I set the cookie only in the HTTP_RESPONSE? Here's the iRule:
static variables defined elsewhere
when HTTP_REQUEST {
if { ( [HTTP::uri] contains "" ) } {
set tableName "table_sessionLimit"
set cookieName "TEST_SessionCookie"
set needCookie 0
if {[HTTP::cookie exists $cookieName]} {
set clientID [HTTP::cookie $cookieName]
if { [table lookup -subtable $tableName $clientID] != "" } {
return
}
}
if { [table keys -subtable $tableName -count] < $static::TEST_max_http_connections} {
set needCookie 1
set clientID [format "%08d" [expr { int(100000000 * rand()) }]]
set clientSocket "[IP::client_addr]_[TCP::client_port]"
table add -subtable $tableName $clientID $clientSocket $static::TEST_sessionTimeout
pool pool-shop
} else {
HTTP::redirect ""
}
} elseif { ( [HTTP::uri] contains "" ) } {
pool pool-portal
} else {
HTTP::close
}
}
when HTTP_RESPONSE {
if {[info exists needCookie]} {
if {$needCookie == 1} {
HTTP::cookie insert name $cookieName value $clientID path "/"
}
}
}