Forum Discussion
C_D_18583
Nimbostratus
Nov 20, 2006Replacing in the URI ; http -> https and port 80 -> 443
What is the easiest way to rewrite the following string? Replacing in the URI http -> https and port 80 -> 443
Before:
https://testlab-d.tdx.dorion.com/amserver/UI/Login?go...
Dec 01, 2006
A couple of comments on your final code
1) If you are going to log the modified value in the response, then use a temporary variable instead of calling the "string map" command twice. Two temporary variables are created and you have the extra overhead of scanning and replacing in the string twice. If you end up removing the log statement then you can leave the HTTP::header replace command as-is.
when HTTP_RESPONSE {
log local0. "response code: [HTTP::status], Location: [HTTP::header Location]"
if { [HTTP::status] starts_with "3" and [HTTP::header "Location"] != ""} {
set new_loc [string map { goto=http% goto=https% %3A80% %3A443% } [HTTP::header "Location"] ]
log local0. "New location: $new_loc"
HTTP::header replace "Location" $new_loc
}
}
2) Since two of your cases in the switch have the same enclosing code, then you can combine them as follows:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/eperformance/*" {
persist source_addr 1800
pool D3_INT1_EMPLOYEE_8
}
"/amserver/*" -
"/amconsole/*" {
persist source_addr 1860
pool D2_INT1_IDENTITY
}
default {
discard
}
}
}
The dash after the string tells the switch to treat it as a logical or between the two. You can combine as many of these as you want together if more come up, just add a dash to the end of each match string with the code tacked on to the last one. Not a big deal, but it does make the rule a bit smaller and more readable.
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects