Forum Discussion

Livius's avatar
Livius
Icon for Altostratus rankAltostratus
Feb 03, 2016

Need help decoding iRule

Hi guys, I inherited the system from ex sys-admin and I found an itneresting iRule which I would like to know the effect for :

 

The irule is as follows :

 

when HTTP_REQUEST { set second [string first "/" [HTTP::uri] 1] incr second if { $second > 0 } { set third [string first "/" [HTTP::uri] $second] if { $third >= 0 } { set uniqueuri [string range [HTTP::uri] 0 $third] persist uie $uniqueuri 28800 } } }

 

Any tips?

 

1 Reply

  • It appears to be a rule designed to create a persistence record based on values from the URI.

     

    I've added syntax formatting and comments to the code below, roughly explaining the logic.

     

    when HTTP_REQUEST {
          Search the URI for a slash (skipping the first character) and record it's index value into the value second.  If it doesn't find another slash, the value of second will be -1
        set second [string first "/" [HTTP::uri] 1]
          Add 1 to second
        incr second
          This if is true unless the search above did not find another slash, at which point the iRule exists without setting a persistence record
        if { $second > 0 } {
              Repeat above looking for a third slash.
            set third [string first "/" [HTTP::uri] $second] 
              Again skips the creation of a persistence record unless a third slash was found
            if { $third >= 0 } { 
                  Create a universal persistence record based on the URI, but only the portion before the third slash
                set uniqueuri [string range [HTTP::uri] 0 $third]
                persist uie $uniqueuri 28800 
            }
        }
    }