Forum Discussion

Sai_131331's avatar
Sai_131331
Icon for Nimbostratus rankNimbostratus
Aug 10, 2016

Irule error-Command not valid in the current scope

My irule is:

 

rule shop_lkqcorp_cache_expiry {

 

when HTTP_REQUEST {

 

if {[HTTP::method] eq "GET" and [HTTP::uri] eq "/"}{ set expire_content_timeout 300 } else { set expire_content_timeout [findclass [string tolower [string range [HTTP::path] [string last . [HTTP::path]] end]] static_cache_24hrs " "] } }

 

when HTTP_RESPONSE { if { $expire_content_timeout ne "" } { HTTP::header replace "Cache-Control" "max-age=$expire_content_timeout, public" HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]" } else {

 

HTTP::header replace "Cache-Control" "private"

HTTP::header replace Expires {-1} } } }

 

My data-group:

 

ltm data-group internal static_cache_24hrs { records { .bmp { data 2678400 } .css { data 2678400 } .gif { data 2678400 } .ico { data 2678400 } .jpeg { data 2678400 } .jpg { data 2678400 } .js { data 2678400 } .pdf { data 2678400 } .png { data 2678400 } .swf { data 2678400 } } type string }

 

I get an error when I put in the iRule: 01070151:3: Rule [/Common/shop_lkqcorp_cache_expiry] error: /Common/shop_lkqcorp_cache_expiry:21: error: [command is not valid in the current scope][}]

 

Can someone help me figure where it is wrong? I am still learning to write iRules and I had tweaked an existing iRule from the Devcentral. Any help is much appreciated!

 

7 Replies

  • This maybe? But I think you'll want to do your "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]" after the if, set it as a variable and then place the variable inside the HTTP::header replace.

        when HTTP_REQUEST {
                if {[HTTP::method] eq "GET" and [HTTP::uri] eq "/"}{ 
                                set expire_content_timeout 300 
                } else { 
                                set expire_content_timeout [findclass [string tolower [string range [HTTP::path] [string last . [HTTP::path]] end]] static_cache_24hrs " "] 
                } 
        }
    
        when HTTP_RESPONSE { 
                if { $expire_content_timeout ne "" } { 
                                HTTP::header replace "Cache-Control" "max-age=$expire_content_timeout, public" HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]" 
                } else {
                                HTTP::header replace "Cache-Control" "private"
                                HTTP::header replace "Expires" "-1"
                } 
        } 
    
    • Sai_131331's avatar
      Sai_131331
      Icon for Nimbostratus rankNimbostratus

      This one didn't work too.

       

      01070151:3: Rule [/Common/shop_lkqcorp_cache_expiry] error: /Common/shop_lkqcorp_cache_expiry:11: error: [wrong args][HTTP::header replace "Cache-Control" "max-age=$expire_content_timeout, public" HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]"

       

    • Sai_131331's avatar
      Sai_131331
      Icon for Nimbostratus rankNimbostratus

      My objective of writing this iRule is that I want to set an Expiry date to static content that needs to be cached by the client's browser.

       

  • This maybe? But I think you'll want to do your "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]" after the if, set it as a variable and then place the variable inside the HTTP::header replace.

        when HTTP_REQUEST {
                if {[HTTP::method] eq "GET" and [HTTP::uri] eq "/"}{ 
                                set expire_content_timeout 300 
                } else { 
                                set expire_content_timeout [findclass [string tolower [string range [HTTP::path] [string last . [HTTP::path]] end]] static_cache_24hrs " "] 
                } 
        }
    
        when HTTP_RESPONSE { 
                if { $expire_content_timeout ne "" } { 
                                HTTP::header replace "Cache-Control" "max-age=$expire_content_timeout, public" HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]" 
                } else {
                                HTTP::header replace "Cache-Control" "private"
                                HTTP::header replace "Expires" "-1"
                } 
        } 
    
    • Sai_131331's avatar
      Sai_131331
      Icon for Nimbostratus rankNimbostratus

      This one didn't work too.

       

      01070151:3: Rule [/Common/shop_lkqcorp_cache_expiry] error: /Common/shop_lkqcorp_cache_expiry:11: error: [wrong args][HTTP::header replace "Cache-Control" "max-age=$expire_content_timeout, public" HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]"

       

    • Sai_131331's avatar
      Sai_131331
      Icon for Nimbostratus rankNimbostratus

      My objective of writing this iRule is that I want to set an Expiry date to static content that needs to be cached by the client's browser.

       

  • Hi Sai,

    the log line...

    error: /Common/shop_lkqcorp_cache_expiry:21: error: [command is not valid in the current scope][}]

    ... states that in line number "21" is a "}" sign too much. 😉

    Cheers, Kai