For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

stevehuffy's avatar
stevehuffy
Icon for Nimbostratus rankNimbostratus
Apr 21, 2015

Problem with output of E-Tag in iRule

Trying to output an E-Tag, the output does not match the input and I can't figure out how to do it. Looks like it should be easy, but have spent too much time on it, so asking here.

My simple iRule to test with:

when HTTP_REQUEST {
   log local0. "test header- [HTTP::header values X-Test]"
}

Test1:

curl http:// -H 'X-Test: "test"'
-
: test header- {"test"}

Test2:

curl http:// -H 'X-Test: W/"test"'
-
: test header- W/\"test\"

I want output to look like this, respectively:

: test header- "test"
: test header- W/"test"

There must be an easy way to do it, I am just not good enough with iRules. TCL lets me do it:

$ tclsh
% puts {"test"}
"test"
% puts W/\"test\"
W/"test"

Please help.

2 Replies

  • just wondering if we can use simple tcl string.

     config
    
    root@(ve11c)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      log local0. "test header- [string map {\\ ""} [HTTP::header values X-Test]]"
    }
    }
    
     /var/log/ltm
    Apr 21 12:41:41 ve11c info tmm1[5649]: Rule /Common/qux : test header- W/"test"
    
  • Yeh, thanks. Was hoping for something more generic that would support other headers, but I guess similar will do for my use case, as E-Tags seem to only have a specific format. I am not sure why HTTP::header adds more characters to the actual HTTP header, but would have thought something like this would have reformatted: [puts [HTTP::header values X-Test]], but can't find anything easily.

    So I am now doing this (hopefully it will provide the original E-Tag ok - it will be going in a 304 response):

    log local0. "from irule HTTP::headers- [HTTP::header values X-Test]"
    log local0. "to get it to original- [string map {\\\" "\""} [string trim [HTTP::header values X-Test] \{\}]]"
    

    Test1

    $ curl http:// -H 'X-Test: "test"'
    -
     : from irule HTTP::headers- {"test"}
     : to get it to original- "test"
    

    Test2

    $ curl http:// -H 'X-Test: W/"test"'
    -
     : from irule HTTP::headers- W/\"test\"
     : to get it to original- W/"test"
    

    Test3 (the iRule doesn't handle this, but hopefully an E-tag is never formatted like this)

    $ curl http:// -H 'X-Test: W/"ba8ba5c\"37e1fce1:0"'
    -
     : from irule HTTP::headers- {W/"ba8ba5c\"37e1fce1:0"}
     : to get it to original- W/"ba8ba5c"37e1fce1:0"