Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Dec 21, 2011

how to use foreach

when HTTP_RESPONSE {

 

set cjj [HTTP::cookie names]

 

 

foreach cjjcookie $cjj {

 

if {$cjjcookie == "how to add 4 cookie name here"

 

}

 

{ Do nothing.

 

}

 

else {

 

HTTP::cookie secure $cjjcookie enable

 

}

 

}

 

}

 

 

I have 4 cookie names need to be specified in ""

 

 

cookie1

 

cookie2

 

cookie3

 

cookie4

 

7 Replies

  • [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b pool foo list
    pool foo {
       members 200.200.200.101:80 {}
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_RESPONSE {
            foreach cjjcookie [HTTP::cookie names] {
                    if {[class match -- $cjjcookie equals unsecure_cookie]} {
                             Do nothing.
                    } else {
                            HTTP::cookie secure $cjjcookie enable
                    }
            }
     }
    }
    [root@ve1023:Active] config  b class unsecure_cookie list
    class unsecure_cookie {
       {
          "cookie1"
          "cookie2"
          "cookie3"
          "cookie4"
       }
    }
    
    [root@ve1023:Active] config  curl -I http://200.200.200.101
    HTTP/1.1 200 OK
    Date: Wed, 21 Dec 2011 07:18:11 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT
    ETag: "4183e4-3e-9c564780"
    Accept-Ranges: bytes
    Content-Length: 62
    Set-Cookie: cookie1=1111; path=/
    Set-Cookie: cookie2=2222; path=/
    Set-Cookie: cookie3=3333; path=/
    Set-Cookie: cookie4=4444; path=/
    Set-Cookie: cookie5=5555; path=/
    Connection: close
    Content-Type: text/html; charset=UTF-8
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79
    HTTP/1.1 200 OK
    Date: Wed, 21 Dec 2011 07:18:17 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT
    ETag: "4183e4-3e-9c564780"
    Accept-Ranges: bytes
    Content-Length: 62
    Set-Cookie: cookie1=1111; path=/
    Set-Cookie: cookie2=2222; path=/
    Set-Cookie: cookie3=3333; path=/
    Set-Cookie: cookie4=4444; path=/
    Set-Cookie: cookie5=5555;secure; path=/
    Connection: close
    Content-Type: text/html; charset=UTF-8
    
    
  • if {[class match -- $cjjcookie equals unsecure_cookie]} {

     

    Do nothing.

     

     

    I am confused by this part.what is the orginal code?
  • I am confused by this part.what is the orginal code?what do you not understand? i just took it from class wiki.

     

     

    class wiki

     

    http://devcentral.f5.com/wiki/iRules.class.ashx
  • oh,I got it ,hehe

     

    when HTTP_RESPONSE {

     

    foreach cjjcookie [HTTP::cookie names] {

     

    if {[class match -- $cjjcookie equals unsecure_cookie

     

     

    ----------------- "--" above betweet match and $cjjcookie should be removed
  • oh,I got it ,hehe

     

    when HTTP_RESPONSE {

     

    foreach cjjcookie [HTTP::cookie names] {

     

    if {[class match -- $cjjcookie equals unsecure_cookie

     

     

    ----------------- "--" above betweet match and $cjjcookie should be removed
  • "--" above betweet match and $cjjcookie should be removednot really. it is safe to put there.

     

     

    -- Terminates option processing (useful if the item or class begins with a hyphen).

     

     

    class wiki

     

    http://devcentral.f5.com/wiki/iRules.class.ashx
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    There are actually several people that suggest using options terminators such as the -- in the class command. In particular when the next argument is a variable it can help ensure that nothing gets misinterpreted. I haven't made it a habit yet, but it certainly doesn't harm anything.

     

     

    Colin