Christian_Meiss
Jul 20, 2016Nimbostratus
class match provides no results
Hi Folks,
i wrote the following iRule Skript which should set HTTP header based on request uri:
when RULE_INIT {
Enable to debug RedirectByLocation translations via log messages in /var/log/ltm
(2 = verbose, 1 = essential, 0 = none)
set static::HeaderByLocationDebug 2
}
when HTTP_REQUEST {
Create all essential variables for the logic below
set all variables to an empty value
set orig_uri [string tolower [HTTP::uri]]
set static::log_prefix "[IP::client_addr]:[TCP::local_port] URI=$orig_uri:"
The name of the Data Group (aka class) we are going to use.
Parse just the virtual server name by stripping off the folders (if present)
set class_name "Substitute_[URI::basename [virtual name]]"
if { $static::HeaderByLocationDebug > 1 } {
log local0. "$static::log_prefix [IP::client_addr]:[TCP::client_port] -> [IP::local_addr]:[TCP::local_port]"
}
set location ""
set header_name ""
set header_value ""
Check whether class_name exist or not.
If it doesn't exists log an that the data group is missing an exiting
if {! [class exists $class_name]} {
log local0. "$log_prefix: Data group $class_name not found, exiting."
return
} else {
Here we know that the needed data group exists and we can go on
set element [class match -element "$orig_uri" starts_with $class_name]
if { $static::HeaderByLocationDebug > 1 } {
if { $element eq "" } {
log local0. "$static::log_prefix no data group element found."
} else {
log local0. "$static::log_prefix data group element found: $element"
}
}
At this point we have a line for the given URI in data group
so we can store each entry in the data group line into a local variable
set location [getfield $element " " 1]
set header_name [string trimleft [getfield $element " " 2 ] "{" ]
set header_value [string trimright [getfield $element " " 3 ] "}" ]
if { $header_name ne "" and $header_value ne "" } {
if { $static::HeaderByLocationDebug > 1} {
log local0. "$static::log_prefix HTTP::header insert $header_name $header_value"
}
HTTP::header insert $header_name $header_value
} elseif { $static::HeaderByLocationDebug > 1 } {
log local0. "$static::log_prefix no header name or value given. Giving up."
}
}
}
Now there seem to be a bug and i have no idea.
set element [class match -element "$orig_uri" starts_with $class_name]
Here no element is found.
Maybe one iRule applied also will interfer these iRule. There also ProxyPass is working on URI's.
/foo -> /bla/basel?abcadef (This is Redirected by ProxyPass) /foo -> should fire a header setting. Content-Disposition "attachement; filename=foo.bar"
Data group list looking like this:
{
records {
/foo {
data "Content-Disposition \"attachement; filename=foo.bar\""
}
/bar {
data "foo bar"
}
}
type string
}
Any ideas please?
Cheers
Christian