Forum Discussion
trouble rewiting path
I need to rewrite the REQUEST path that is returned to the browser. I have an irule which reads the REQUEST path, splits it into a variable which has the path I want (I logged it to my logging server so I know it contains what I want. I am having trouble with getting the HTTP::path modified.
First use hsl::open to define where to send logs and save it as a variable HSLwhen CLIENT_ACCEPTED { set hsl [HSL::open -proto UDP -pool graylog2-syslog-pool] }
when HTTP_REQUEST {
create variable to hold modified path, split on ;jsessionidset nojsession [getfield [HTTP::path] ";jsessionid=" 1]
Check if the path contains a jsessionid
if {[HTTP::path] contains ";jsessionid"}{
write to log verify that the if clause and the variable are correct
HSL::send $hsl "webmod This is the $nojsession without sessionid"
replace the path with the variable (modified path without jsessionid)
HTTP::path $nojsession
}
}
- rob_carr
Cirrocumulus
when CLIENT_ACCEPTED { set hsl [HSL::open -proto UDP -pool graylog2-syslog-pool] } when HTTP_REQUEST { create variable to hold modified path, split on ;jsessionid set nojsession [getfield [HTTP::path] ";jsessionid=" 1] Check if the path contains a jsessionid if {[HTTP::path] contains ";jsessionid"}{ write to log verify that the if clause and the variable are correct HSL::send $hsl "webmod This is the $nojsession without sessionid" replace the path with the variable (modified path without jsessionid) HTTP::path $nojsession } }
- Andy_McGrath
Cumulonimbus
A few issues with your iRule, you are looking at the HTTP::path for a Query parameter which will never exist. Lets say the request is
You would get the following returned from different iRule commands:https://some.host.com/this/is/the/path?jsessionid=thequerypart
- HTTP::host =
some.host.com
- HTTP::path =
/this/is/the/path
- HTTP::uri =
/this/is/the/path?jsessionid=thequerypart
- HTTP::query =
jsessionid=thequerypart
Your iRule would never find locate the
query and is only updating the HTTP path not the query.jsessionid
The following iRule does the same but using
instead ofHTTP::uri
:HTTP::path
First use hsl::open to define where to send logs and save it as a variable HSL when CLIENT_ACCEPTED { set hsl [HSL::open -proto UDP -pool graylog2-syslog-pool] } when HTTP_REQUEST { Check if the URI contains a jsessionid if {[HTTP::uri] contains ";jsessionid="}{ Create variable to hold modified URI, split on ;jsessionid set nojsession [getfield [HTTP::uri] ";jsessionid=" 1] Write to log verify that the if clause and the variable are correct HSL::send $hsl "webmod This is the $nojsession without sessionid" Replace the URI with the variable (modified URI without jsessionid) HTTP::uri $nojsession } }
Quick note about this iRule if the request contains any query parameters after the
then they will be lost as thejsessionid
command only takes the first part of the URI.getfield
e.g. If the URI requested is
the updated request would be/this/is/the/path?page=test;jsessionid=thequerypart;user=bob
and the query parameter/this/is/the/path?page=test
would be lost.user=bob
- HTTP::host =
Recent Discussions
Related Content
* 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