Forum Discussion

user1115_113077's avatar
user1115_113077
Icon for Nimbostratus rankNimbostratus
Jun 25, 2011

Help with Cookie Insertion

Hello,

 

 

Currently we're using the following on a vs,

 

 

when HTTP_REQUEST {

 

if { [HTTP:uri] starts_with "/clasee*"} {

 

pool class}

 

else {

 

pool main}

 

}

 

 

We need to add a cookie when request comes in from certain source IPs; we've tried this with no luck so far

 

 

when HTTP_REQUEST {

 

if { [matchclass [IP::client_addr] equals "$::class_ip"] } {HTTP::cookie insert name "class" value "class"}

 

elseif { [HTTP:uri] starts_with "/clasee*"} {pool class}

 

else {pool main}

 

}

 

 

 

Thanks for any help in advance

 

 

 

 

 

4 Replies

  • Hi User 1115,

     

    I think the issue might be in the logic of what are yo trying to do.

     

     

    According to your iRule the logic works like this:

     

    If client ip matches the class_ip datagroup, apply the Cookie Insert and then EXIT the iRule. (NOTE: It will not evaluate the rest of the iRule)

     

    If client ip does not match the class_ip datagroup, and if the uri starts with "/clasee" then go to pool called class and EXIT the iRule. (NOTE: No Cookie Insert will be invoked)

     

    If client ip does not match and your URI does not start with /clasee then go to pool main and EXIT the iRule. (NOTE: No cookie Insert will be invoked)

     

     

    Is this logic you want?.

     

     

    Bhattman
  • Bhattman,

     

    Thank you for tte explaination and clearly that's not what we want.

     

     

    We need to:

     

    If the client matches the class_ip datagroup, apply the coookient insert AND continue to check the uri, if the uri starts with "/class" go to pool call class, if the uri does not start with "/class" go to pool main and exit the irule. (has cookie)

     

    If the client does not matches the class_ip datagroup, check the uri, if the uri starts with "/class" go to pool cll class if the uri does not start with "/class" go to pool main and exit the irule. (no cookie)

     

     

    We appreicate any help with any rule for the above logic, we're first time irule user.

     

     

    Best regards,

     

     

     

  • Hi User1115,

     

    In that case one of the ways you can do this is the following codes

     

     

     

    This is for version 9.x.x

     

     

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [matchclass [IP::client_addr] eq $::class_ip] } {

     

    HTTP::cookie insert name "class" value "class"

     

    }

     

     

    Choose a pool based on URI

     

    if { [HTTP:uri] starts_with "/clasee*"} {

     

    pool class

     

    } else {

     

    pool main

     

    }

     

    }

     

     

     

    OR Using a switch statement

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [matchclass [IP::client_addr] eq $::class_ip] } {

     

    HTTP::cookie insert name "class" value "class"

     

    }

     

    Choose a pool based on URI

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/clasee*" { pool class }

     

    default { pool main }

     

    }

     

    }

     

     

     

     

    If you are going to v10 then the code would like like the following

     

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [class match [IP::client_addr] equals "class_ip" } {

     

    HTTP::cookie insert name "class" value "class"

     

    }

     

     

    Choose a pool based on URI

     

    if { [HTTP:uri] starts_with "/clasee*"} {

     

    pool class

     

    } else {

     

    pool main

     

    }

     

    }

     

     

     

    OR Using a switch statement for v10

     

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [class match [IP::client_addr] equals "class_ip"] } {

     

    HTTP::cookie insert name "class" value "class"

     

    }

     

    Choose a pool based on URI

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/clasee*" { pool class }

     

    default { pool main }

     

    }

     

    }

     

     

    I hope this helps

     

     

    Bhattman

     

     

  • Hi User1115,

     

    For debugging you can do the following:

     

     

    This is for version 9.x.x

     

     

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [matchclass [IP::client_addr] eq $::class_ip] } {

     

    HTTP::cookie insert name "class" value "class"

     

    log local0. "The Source IP: [IP::client_addr] matched. Inserting Cookie"

     

    }

     

    Choose a pool based on URI

     

    if { [HTTP::uri] starts_with "/clasee*"} {

     

    log local0. "The URL is [HTTP::uri] which is selecting pool class"

     

    pool class

     

    } else {

     

    log local0. "the URL is [HTTP::uri] which is selecting pool main"

     

    pool main

     

    }

     

    }

     

     

     

    OR Using a switch statement

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [matchclass [IP::client_addr] eq $::class_ip] } {

     

    log local0. "The Source IP: [IP::client_addr] matched. Inserting Cookie"

     

    HTTP::cookie insert name "class" value "class"

     

    }

     

    Choose a pool based on URI

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/clasee*" {

     

    pool class

     

    log local0. "The URL is [HTTP::uri] which is selecting pool class"

     

    }

     

    default {

     

    pool main

     

    log local0. "the URL is [HTTP::uri] which is selecting pool main"

     

    }

     

    }

     

    }

     

     

     

     

    If you are going to v10 then the code would like like the following

     

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [class match [IP::client_addr] equals "class_ip" } {

     

    HTTP::cookie insert name "class" value "class"

     

    log local0. "The Source IP: [IP::client_addr] matched. Inserting Cookie"

     

    }

     

     

    Choose a pool based on URI

     

    if { [HTTP::uri] starts_with "/clasee*"} {

     

    pool class

     

    log local0. "The URL is [HTTP::uri] which is selecting pool class"

     

    } else {

     

    pool main

     

    log local0. "the URL is [HTTP::uri] which is selecting pool main"

     

    }

     

    }

     

     

     

    OR Using a switch statement for v10

     

     

     

    when HTTP_REQUEST {

     

    Insert cookie if it matches the CLASS_IP datagroup

     

    if { [class match [IP::client_addr] equals "class_ip"] } {

     

    HTTP::cookie insert name "class" value "class"

     

    log local0. "The Source IP: [IP::client_addr] matched. Inserting Cookie"

     

    }

     

    Choose a pool based on URI

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/clasee*" {

     

    pool class

     

    log local0. "The URL is [HTTP::uri] which is selecting pool class"

     

    }

     

    default {

     

    pool main

     

    log local0. "the URL is [HTTP::uri] which is selecting pool main"

     

    }

     

    }

     

    }

     

     

    I hope this helps

     

     

    Bhattman