Forum Discussion

Rob_Morhaime_11's avatar
Rob_Morhaime_11
Icon for Nimbostratus rankNimbostratus
Aug 20, 2008

Simple iRule not working - is it my "string map" syntax?

This seems like a simple iRule, but when applied I get socket errors. Here's the rule:

 
 when HTTP_RESPONSE  { 
 if { [HTTP::is_redirect] }{ 
 if { [HTTP::header Location] contains "PageMustBeSecure.htm" }{ 
 HTTP::header replace Location "[string map -nocase {"http://" "https://"} [HTTP::header Location]]" 
 } 
 } 
 } 
 

Is it the quotes in my string map? I swear I saw that syntax somewhere, but now I can't find it. The LTM is running 9.1.0.

4 Replies

  • Hi,

    This may be due to the quotes. You should check /var/log/ltm for a more detailled message

     
      when HTTP_RESPONSE  {  
      if { [HTTP::is_redirect] }{  
      if { [HTTP::header "Location"] contains "PageMustBeSecure.htm" }{  
      HTTP::header replace "Location" [string map -nocase {"http://" "https://"} [HTTP::header "Location"]]  
      }  
      }  
      }  
     

    If it doesn't work try this:

     
      when HTTP_RESPONSE  {  
      if { [HTTP::is_redirect] }{  
                    log local0. "is redirect -> [HTTP::header "Location"]" 
      if { [HTTP::header "Location"] contains "PageMustBeSecure.htm" }{  
                             log local0. "redirect contains PageMustBeSecure.htm " 
      HTTP::header replace "Location" [string map -nocase {"http://" "https://"} [HTTP::header "Location"]]  
                            log local0. "new redirect is: [HTTP::header "Location"]" 
      }  
      }  
      }  
     

    and tell us the output of the /var/log/ltm file

  • I'll try your suggestions tonight.

     

     

    However, I found the article that does almost exactly what I want. It uses the same syntax (and same quote nesting) as my iRule used.

     

     

    See the second code example here:

     

    http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=220

     

     

    Thanks!

     

    Rob
  • Well, the logging statements helped. Thank you for that suggestion. Here's the output:

     

     

    Aug 21 18:29:11 tmm tmm[725]: 01220001:3: TCL error: Rule my_rule - invalid command name "HTTP::is_redirect" while executing "HTTP::is_redirect"

     

     

    So, HTTP::is_redirect isn't supported? We're running 9.1.0 and this article suggests it *is* supported:

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__is_redirect.html

     

     

    Any ideas? Documentation error?

     

     

     

    fyi: I got my rule working by using [HTTP::status] contains "302" instead.
  • spark_86682's avatar
    spark_86682
    Historic F5 Account
    It's sort-of a documentation error. It turns out that the HTTP::is_redirect function framework was in 9.0.0, but some important code was left out. The documentation is often based on the framework, though, which is why it says that 9.0.0 has that command. That's also the reason that you get a runtime error, but not an error when you load the configuration. I'll update the wiki.

     

     

    You could use "HTTP::header is_redirect", though; it's the same code underneath as HTTP::is_redirect.