Forum Discussion

Peter_74's avatar
Peter_74
Icon for Nimbostratus rankNimbostratus
Oct 23, 2015

Serving UTF-8 content from iRule?

Do iFiles or iRules have any known issues with UTF-8 content? I can't find mention either way in the documentation or online.

I am trying to set up an iRule to serve a maintenance page that contains unicode text. For example:

現在メンテナンス中の為

The actual text is a bit longer but would reveal the site in question.

The utf-8 text cannot be included directly in the iRule because TCL validation fails, complaining of unbalanced braces.

I've tried placing the text in an iFile to get around the TCL validation errors. But then the text delivered to the browser is corrupted. I confirmed with curl that the Content-Type response header indicates UTF-8, and for good measure I set the meta http-equiv in the text of the response as well. I even manually forced Firefox to render the page as UTF-8 text.

When I logged the text returned from the iFile inside the iRule, the same corrupted text appears there. My terminal is set to UTF-8, as confirmed by viewing the text in the source file used to create the iFile.

Has anyone successfully served UTF-8 content from an iRule?

We're running 11.5.1 HF9.

Here is a stripped-down version of the iRule that demonstrates the issue. The referenced iFile contains the Unicode "SNOWMAN" character.

ltm rule utf8_test_minimized {
    when HTTP_REQUEST {

  set ifilename "unicode-snowman"

  if { 1 } {
    HTTP::respond 200 content [format {
    
      
      UTF-8 iRule Test
      
         iFile Test: "%s".
         Should look like this: "&9731" (HTML encoded using numeric character reference)
      
    } [ifile get $ifilename]] Content-Type "text/html; charset=utf-8"
    log local0. "Test: \"[ifile get $ifilename]\""
    return
  }

}
}

4 Replies

  • (This is a repost of a previous question because I could not edit the question to include the unicode text and iRule. The original has been deleted)
  • FYI, executing the iRule generates the following log message: Oct 23 12:18:34 (redacted) info tmm3[11364]: Rule /Common/utf8_test_minimized : Test: "&226; " (comment formatting is encoding the quote characters)
  • Hi

    I tried this rule on 11.5.3 and it worked:

    when HTTP_REQUEST {
       HTTP::respond 200 content {
        
          
          UTF-8 iRule Test
          
             Should look like this: "&9731" (HTML encoded using numeric character reference)
          &29694;&22312;&12513;&12531;&12486;&12490;&12531;&12473;&20013;&12398;&28858;
        
        
        } Content-Type "text/html; charset=utf-8"
    }
    

    Hope that helps! 🙂

    /Patrik

  • Ah, sorry for the misunderstanding. I think it's a tall order to ask for this though. I can imagine parsing and validating TCL is a pain in the *ss as it is. :)

     

    Have you considered putting the message in an iFrame letting the client update a static page themselves?

     

    /Patrik