Forum Discussion
Help deleting header name that contains curly braces
- Nov 18, 2022
I think I just figured it out guys Mohamed_Ahmed_Kansoh CA_Valli
Paste this and run it. It worked out for me. Now any of you can explain why this works?? Is this a bug with F5? At least it seems to me. If it is, how can I let them know so they can fix it.
when HTTP_REQUEST { if { [HTTP::uri] eq "/demo2" } { HTTP::header insert "{esbsoapheader}userName" "spencer" foreach aHeader [HTTP::header names] { log local0. "HTTP Request Headers: $aHeader: [HTTP::header value $aHeader]" } log local0. "***************REMOVING BAD HEADER************" HTTP::header remove "\\{esbsoapheader\\}userName" foreach aHeader [HTTP::header names] { log local0. "HTTP Request Headers: $aHeader: [HTTP::header value $aHeader]" } } }
Amazing thing in iRules, you can submit to the original factory that this is a bug to be optimized or that iRules has a strange bug with "{" or "}" in the HTTP header
It may also be a disadvantage of the TCL language. Lists can be represented by "" or {}, which can sometimes be ambiguous, unlike Python lists, which can only be represented by []
Some manufacturers' load balancing scripts use lua language instead of tcl
I found that as long as the name field in the HTTP header contains { or }, HTTP:: header remove will report an error,
It seems that HTTP:: header remove name, name value refers to the value in HTTP:: header names storage format, rather than the value of variable string that we usually understand
log local0. "names is: [HTTP::header names]" the log result is:
names is: Host User-Agent Accept {{esbsoapheader}userName} Connection {{esbsoapheader}userName}
HTTP header name {esbsoapheader}userName the storage format in [HTTP::header names] is {{esbsoapheader}userName}
so, we need to use this format HTTP::header remove {{{esbsoapheader}userName}} or
HTTP::header remove "{{esbsoapheader}userName}"
use HTTP::header remove {{esbsoapheader}userName} will raise error!
if we HTTP::header insert "\{esbsoapheaderuserName" "f5-gtm"
the [HTTP::header names] running result is:
names is: Host User-Agent Accept \{esbsoapheaderuserName Connection
we need to this format to remove:
HTTP::header remove {\{esbsoapheaderuserName}
It seems that in the list of tcl, the element storage that contains { or } needs to carry {}
(bin) 49 % set a {Host User-Agent Accept {esbsoapheader}userName Connection}
Host User-Agent Accept {esbsoapheader}userName Connection
(bin) 50 % lindex $a 3
list element in braces followed by "userName" instead of space
(bin) 51 % string length $a
57
(bin) 53 % set a "Host User-Agent Accept {esbsoapheader}userName Connection"
Host User-Agent Accept {esbsoapheader}userName Connection
(bin) 55 % lindex $a 1
list element in braces followed by "userName" instead of space
(bin) 56 %
(bin) 57 % set a {Host User-Agent Accept {{esbsoapheader}userName} Connection}
Host User-Agent Accept {{esbsoapheader}userName} Connection
(bin) 62 % lindex $a 3
{esbsoapheader}userName
(bin) 63 % set qq "Host User-Agent Accept {{esbsoapheader}userName} Connection"
Host User-Agent Accept {{esbsoapheader}userName} Connection
(bin) 64 % lindex $qq 3
{esbsoapheader}userName
(bin) 65 %
(bin) 95 % set names_list {Host User-Agent Accept \{esbsoapheader\}userName Connection}
Host User-Agent Accept \{esbsoapheader\}userName Connection
(bin) 97 % lindex $names_list 3
{esbsoapheader}userName
(bin) 98 %
(bin) 70 % set names "Host User-Agent Accept \\{esbsoapheader\\}userName Connection"
Host User-Agent Accept \{esbsoapheader\}userName Connection
(bin) 71 % lindex $names 3
{esbsoapheader}userName
when HTTP_REQUEST {
if { [HTTP::uri] eq "/demo2" } {
HTTP::header insert "\{esbsoapheaderuserName" "spencer"
HTTP::header insert Connection close
HTTP::header insert "{esbsoapheader}userName" "f5-bigip"
foreach aHeader [HTTP::header names] {
log local0. "HTTP Request Headers: $aHeader: [HTTP::header value $aHeader]"
}
log local0. "exists header: [HTTP::header exists "{esbsoapheader}userName"]; value is [HTTP::header "{esbsoapheader}userName"]"
log local0. "names is: [HTTP::header names]"
log local0. "***************REMOVING BAD HEADER************"
# set a "{esbsoapheader}userName"
# HTTP::header remove [list $a]
# HTTP::header remove "{{esbsoapheader}userName}" it also works correct
HTTP::header remove {{{esbsoapheader}userName}}
HTTP::header remove {\{esbsoapheaderuserName}
foreach aHeader [HTTP::header names] {
log local0. "HTTP Request Headers: $aHeader: [HTTP::header value $aHeader]"
}
}
}
- CA_ValliNov 19, 2022MVP
Thanks for sharing this! I thought the issue could be something like this but I did not have time to look into this further.
Well, you never stop learning! 😜
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com