Forum Discussion
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?
- hooleylistCirrostratusOriginal post:
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 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_REPLACESep 21 22:08:42 local/tmm5 info tmm5[7234]: Rule URI_STRING_REPLACE$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? - hooleylistCirrostratusHi Vince,
- Vince_Beltz_959NimbostratusThanks, Hoolio - I updated my post to show a value being set for $httpuri - this is being excerpted from a larger rule. Point taken on set HTTP:uri v. just HTTP:uri, but my main problem seems to be with:
- hooleylistCirrostratusThis should work fine:
when HTTP_REQUEST priority 501 { log local0. "[IP::client_addr]:[TCP::client_port]: 501: Updated \[HTTP::uri\]: [HTTP::uri]" }
- Vince_Beltz_959NimbostratusThanks again for the extra logging tip Hoolio - the rewrite is indeed happening, but I'm not getting the page I should be, so the problem must be elsewhere.
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