Forum Discussion

Greg_33558's avatar
Greg_33558
Icon for Nimbostratus rankNimbostratus
Jun 23, 2015

Equivalent of TCL {*} list expansion for iRules?

iRules (LTM 11.6 HF4) don't appear to support TCL list expansion e.g. {*} or {expand}. I'm trying to concatenate two lists, and the default behavior of lappend is to leave the appended list unexpanded. In TCL 8.5+ the list is expanded using {*}:

tclsh8.6 [~]set foo {a}
a
tclsh8.6 [~]lappend foo [split "b c"]
a {b c}
tclsh8.6 [~]lappend foo {*}[split "d e"]
a {b c} d e
tclsh8.6 [~]lindex $foo 2
d
tclsh8.6 [~]

Any ideas how to do this? I have a list of default coded in an iRule, and would like to allow entries to be appended to the list based on a string variable in a data group.

set http_headers {host content-length content-type referer}
lappend http_headers [split [class lookup more_headers config-datagroup]]    

where more_headers is "user-agent accept"... but right now I think I end up with:

{host content-length content-type referer {user-agent accept}}

2 Replies

  • do it with a loop:

    foreach headers [split [class lookup more_headers config-datagroup]] {
    lappend http_headers $headers
    }
    
  • I ended up using concat as the most efficient method from Concatenating Lists:

    set http_headers [concat {host content-length content-type referer} \
                      [class lookup more_headers config-datagroup]]
    

    This tested out properly in cases where more_headers was unset, set but empty, and set with values.