Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

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?

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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 
        }
    }
}
1
Comments on this Answer
Comment made 03-Feb-2016 by Theo 380
I'll add that this is likely an application requirement--I'd talk to that development group about any requirements for it.
0