Forum Discussion

danielc's avatar
danielc
Icon for Cirrus rankCirrus
Jun 30, 2022

Is there any string function that can calculate how many characters in a data variable in irule?

Hello,

For example I would like to know how many characters in [HTTP:uri] , is it possible to do so?

Thanks

 

    • danielc's avatar
      danielc
      Icon for Cirrus rankCirrus

      Hello,

      I have given it a try but faced problem:

      when HTTP_REQUEST {

      set thisuri [HTTP::uri]

      ...

      }

       

      when HTTP_RESPONSE {

      if { [HTTP::status] == 404 } {


      if { [ string length $thisuri ] > 2 } {

      HTTP::respond 404 content "
      <html>
      <head>
      <title>Not Found</title>
      </head>
      <body>
      <h2>Not Found</h2>
      This page is not found.<br>
      <p></p>
      </body>
      </html>


      } else {

      HTTP::respond 404 content "
      <html>
      <head>
      <title>Not Found</title>
      </head>
      <body>
      <h2>Not Found</h2>
      This website is not found.<br>

      <p></p>
      </body>
      </html>
      "
      }
      }

       

      But I faced this error

      01070151:3: Rule [/Common/check_url] error: /Common/check_url:63: error: [parse error: missing "]["

      line 63 is  HTTP::respond 404 content "

      line 61 is  if { [string length $thisuri] > 2 } then {

      Any idea? Thanks

  • You are missing a quotation mark (") after </html> in the if clause.
    May i suggest, that you use a "real" editor to write iRules.
    Maybe try VScode with the extension "F5 Network iRules". With propper syntax highlighting errors like this are more easy to spot.

     

    • danielc's avatar
      danielc
      Icon for Cirrus rankCirrus

      Thanks for your suggestion, I am using it, It is too difficult to do the irule programming directly on bigip.