Problem this snippet solves:
This iRule was written with the goal to persist on only the last jsessionid that is present when multiple jsessionid HTTP Paremeters are present..
How to use this snippet:
I ran into a particular challenge where a customer was receiving a request where a jsessionid was expected to be set in an HTTP Request Parameter.
-
For those of you who are not familiar, see where the parameters lye below:
<scheme>://<username>:<password>@<host>:<port>/<path>;<parameters>?<query>#<fragment>
REF: What Every Developer Should Know About URLs - Skorks
Here is an example of a full request:
http://www.example.com/my/resource.html;jsessionid=0123456789abcdef;jsessionid=0123456789abcdef?alice=mouse
In the above example, there are two jsessionid parameters, both of which are the same value.
This is what was being used to Persist
"*jsessionid*" {
#Parse the URI and look for jsessionid. Skip 11 characters and match up to the next "?"
set session_id [findstr [HTTP::uri] jsessionid 11 "?"]
}
Code :
when CLIENT_ACCEPTED {
set debug 1
}
when HTTP_REQUEST {
set logTuple "[IP::client_addr]:[TCP::client_port] - [IP::local_addr]:[TCP::local_port]"
set parameters [findstr [HTTP::path] ";" 1]
set session_id ""
foreach parameter [split $parameters ";"] {
scan $parameter {%[^=]=%s} name value
if {$debug}{log local0.debug "$logTuple :: Multiple JsessionID in: [HTTP::host][HTTP::uri]"}
if {$name equals "jsessionid"} {set session_id $value}
}
if {$session_id ne ""}{
#Persist on the parsed session ID for X seconds
if {$debug}{log local0.debug "$logTuple :: Single JsessionID in: [HTTP::host][HTTP::uri]"}
persist uie $session_id 86400
}
}