String Map Fail?
I'm trying to build a function allowing search-and-replace of substrings within a URI.
Class:
class URI_STRING_REPLACE_LIST {
"/coupons/" { "/promotions/offers/coupons/signin.go" }
}
Rule:
when HTTP_REQUEST {
set httpuri [string tolower [HTTP:uri]]
set urisearch ""
set urireplace ""
set newuri ""
set urisearch [class match -name $httpuri contains URI_STRING_REPLACE_LIST]
set urireplace [class match -value $urisearch contains URI_STRING_REPLACE_LIST]
log local0.info "URI-Replace1 Search: $urisearch Replace: $urireplace"
if { ( ( $urisearch ne "" ) and ( $urireplace ne "" ) ) } {
set $newuri [string map [list $urisearch $urireplace ] $httpuri]
log local0.info "URI-Replace2 New: $newuri URI: [HTTP::uri]"
set HTTP::uri $newuri
return
}
}
Log:
Sep 21 22:08:42 local/tmm5 info tmm5[7234]: Rule URI_STRING_REPLACE : URI-Replace1 Search: /coupons/ Replace: /promotions/offers/coupons/signin.go
Sep 21 22:08:42 local/tmm5 info tmm5[7234]: Rule URI_STRING_REPLACE : URI-Replace2 New: URI: /coupons/
$urisearch and $urireplace are matching, the string map to set $newuri (though I thought I was seeing it work in the logs earlier) is failing. I tried adding list to the string map statement after finding it referred to in another thread here, but it doesn't seem to help. I'd also tried setting HTTP:uri with the string map directly, but added $newuri trying to troubleshoot. Any ideas why string map doesn't seem to work, or something to use instead?