Forum Discussion

amebiz_142234's avatar
amebiz_142234
Icon for Nimbostratus rankNimbostratus
May 24, 2018

override variables

example

when HTTP_REQUEST {
set var "foo"
if { [HTTP::uri start_with "/foobar"] } {
    set var "bar"
    }
}

when HTTP_RESPONSE {
log 1.1.1.1 "logging $var"
}

Hi guys, for all requests which they are not start_with /foobar will be logged with "foo".

But if there a Request matched with /foobar* then there will be also logged "foo" but that should be logged with "bar"

whats going wrong here? can i not overrides existing var's? or is there a special syntax for it?

2 Replies

  • Hi,

    of course you can override var... try this:

    when HTTP_REQUEST {
    
    if { [string tolower [HTTP::uri]] start_with "/foobar" } {
        set var "bar"
    } else {
        set var "foo"
    }
    
    }
    
    when HTTP_RESPONSE {
    
    log 1.1.1.1 "logging $var"
    }
    
  • Hi,

    the issue is this line:

    if { [HTTP::uri start_with "/foobar"] } {
    

    You must use

    [HTTP::uri]
    to get URI from HTTP request, then compare it with expected URI (move the close bracket from the end of the line to just after HTTP::uri)

    if { [HTTP::uri] start_with "/foobar" } {