Forum Discussion

vmunier_96939's avatar
vmunier_96939
Icon for Nimbostratus rankNimbostratus
Oct 22, 2013

Problem to create a cookie session

Hi, I'm a beginner with Irules and I have a problem to create a cookie session with Irules. In my Irules, i have the following code:

 

 

But the problem is the cookie is not created. The irule is however well executed because i see the "insert cookie line" in the log. I do not see what is wrong?? because this seems to be very simple operation...I looking for a similar problem on the devcentral but i found nothing. Thank you for your help. Vincent

 

2 Replies

  • I suspect you're looking on the client for the cookie, but your cookie insertion code is being set in the HTTP request, so the cookie is getting sent to the server. If you want the cookie at the client, you have a few options depending on how you want the traffic to flow.

    If you want the server to respond to the "?LastAuthFailed" URI (option 1), then you would set a flag in the HTTP_REQUEST event and set the cookie in the HTTP_RESPONSE event.

    If you want the BIG-IP to handle the "?LastAuthFailed" URI (option 2), (ie. a redirect or some arbitrary code), then you can set the cookie in the HTTP_REQUEST event using the HTTP::respond command.

     

    # Option 1
    when HTTP_REQUEST {
        if { [HTTP::uri] ends_with "?LastAuthFailed=1" } {
            set setcookie 1
        }
    }
    when HTTP_RESPONSE {
        if { [info exists setcookie] } {
            unset setcookie
            HTTP::cookie insert name "MyCookie" value "toto"
            HTTP::cookie path "MyCookie" "/"
        }
    }
    # Option 2
    when HTTP_REQUEST {
        if { [HTTP::uri] ends_with "?LastAuthFailed=1" } {
            HTTP::respond 200 content "..." "Set-Cookie" "MyCookie=toto; path=/"
        }
    }