Forum Discussion

ItayG_188662's avatar
ItayG_188662
Icon for Nimbostratus rankNimbostratus
Aug 02, 2018

iRule variable not being reset

Hello guys, I've the following iRule:

when HTTP_REQUEST {
    if {[HTTP::uri] starts_with "/someuri"} {        
        set time_to_change 1
        }
     }
when HTTP_RESPONSE {
    if {[info exists time_to_change]} {
        do something..
        }
      }
when HTTP_RESPONSE_DATA {
    if {[info exists time_to_change]} {
        do something..
      }
     }

What I've notice that if i set variable on particular request which is match on my if condition and if subsequent request is being sent to VS which doesn't match on the condition BUT it has the same connection (SPORT+ DPORT) the variable isn't being reset although it's different request, but if the subsequent request is being sent with different SPORT the variable being reset as expected.

I was looking around and i found this thread:

https://devcentral.f5.com/questions/disable-irule-process-for-the-request-not-for-the-whole-tcp-connection?lc=1

variable has been set in request 1 will not be messed up even request 2 comes in earlier than response 1.

but from my debugging logs it's look like my response being sent back to client before the second request so it should get reset:

: variable should be 1 and got 1 this is the URI /MATCH_ON_CONDITION_URI the sport is 55389 clock clicks 55042962
: HTTP_RESPONSE HAPPENED the port is 55389 clock clicks 55042962
: variable should be 0 and 1 and /NOT_MATCH_CONDITION_URI the port is 55389 clock clicks 55229758
: HTTP_RESPONSE HAPPENED the port is 55389 clock clicks 55229758

Can anyone explain me what I'm missing? by the way i was able to solve this problem by adding

unset time_to_change
at the end of HTTP_RESPONSE_DATA event.

Thanks in advance.

1 Reply

  • This is the expected behavior!

     

    Variable is set for the whole tcp connection, and every requests within this connection!

     

    To solve your issue, change the code to

     

    when HTTP_REQUEST {
        if {[HTTP::uri] starts_with "/someuri"} {        
            set time_to_change 1
            } else {        
            set time_to_change 0
            }
         }