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 HSL

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
}

}

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
  }
}

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

https://some.host.com/this/is/the/path?jsessionid=thequerypart

You would get the following returned from different iRule commands:

  • 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

jsessionid

query and is only updating the HTTP path not the query.

The following iRule does the same but using

HTTP::uri

instead of

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

jsessionid

then they will be lost as the

getfield

command only takes the first part of the URI.

e.g. If the URI requested is

/this/is/the/path?page=test;jsessionid=thequerypart;user=bob

the updated request would be

/this/is/the/path?page=test

and the query parameter

user=bob

would be lost.