Forum Discussion

vivek_76299's avatar
vivek_76299
Icon for Nimbostratus rankNimbostratus
Jul 08, 2010

how to extracting part of a header

Hi All,

 

 

There is a HTTP header "ROUTE=Poison^Abb^POISON007;TCS^Abb^CL02;Virtual^Abb^VPOOL1" or "ROUTE=TLL^Add^CL02;Virtual^Abb^VPOOL2". How can i extract the "Virtual^Abb^XXXXX" from the header. I read that substr is not recommended to use with the optional 3rd parameter. Please let me know the how the above value can be obtained in an iRule.

1 Reply

  • If there are arbitrary numbers of fields in between the ^'s, most string/scan operations wouldn't work. Is there a pattern that you want to parse the two fields between the carets after Virtual^?

     

     

    getfield would work to split the string on the string ;virtual^. You could then break up the last half on the ^. Here's an untested snippet:

     

     

    set tmp [getfield [HTTP::header route] {;virtual^} 2]

     

    log local0. "Parsed [HTTP::header route] to $tmp"

     

    scan $tmp {^%[^^]^%[^^]} a b

     

    log local0. "Parsed $tmp to $a and $b"

     

     

    If that works, you can skip the intermediate variable:

     

     

    scan [getfield [HTTP::header route] {;virtual^} 2] {^%[^^]^%[^^]} a b

     

    log local0. "Parsed [HTTP::header route] to $a and $b"

     

     

    Aaron