Forum Discussion
Pirlo
Nimbostratus
Dec 30, 2014URI inspect - Rewrite - Redirect
DevGods
I am trying to inspect URI and Insert into a newly formatted redirect. I am trying to use the URI Interrogation code to dump the params then formulate the redirect.
If I read the co...
StephanManthey
Nacreous
Dec 31, 2014I noticed a mistake in my first sample (missing variable declaration in response definition).
(For whatever reason I cannot change the previous post.)
Here is the corrected code including a switch for turning debugging on/off and allowing both ampersand and semicolon for parameter separation in query:
when HTTP_REQUEST {
enable (1), disable (0) debugging
set debug 0
if {[HTTP::query] ne "" && !([HTTP::query] starts_with "ReceiptLocator") } {
split query into parameters separated by semicolon or ampersand
set namevals [split [HTTP::query] ";&"]
if { $debug > 0 } {
log local0. "original query: <[HTTP::query]>; number of params: <[llength ${namevals}]>"
}
loop through all parameters
for {set i 0} {$i < [llength ${namevals}]} {incr i} {
read parameter name and value
set param [split [lindex ${namevals} $i] "="]
if { $debug > 0 } {
log local0. "current parameter: <$param>, <[expr {${i} + 1}]> of <[llength ${namevals}]>"
log local0. "param_name: <[lindex $param 0]>, param_value <[lindex $param 1]>"
}
assign variable values for redirect
switch [string tolower [lindex $param 0]] {
"receiptlocator" { set ReceiptLocator [lindex $param 1] }
"origincity" { set CityOrigin [lindex $param 1] }
"firstname" { set FirstName [lindex $param 1]}
"lastname" {set LastName [lindex $param 1]}
}
}
redirect only if variables are set
if { [info exists ReceiptLocator] && [info exists CityOrigin] && [info exists FirstName] && [info exists LastName] } {
HTTP::redirect "HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::path]?ReceiptLocator=${ReceiptLocator}&CityOrigin=${CityOrigin}&FirstName=${FirstName}&LastName=${LastName}"
} else {
if { $debug > 0 } {
log local0. "missing parameters in query"
}
}
} else {
if { $debug > 0 } {
log local0. "no query data or query already in expected format"
}
}
}
For testing locally on the F5 device I´m using the same approach as Nitass:
curl -i http://10.131.131.120/test?receiptLocator=ABCDEF\;originCity=BOS\;firstName=John\&lastName=Doe\;language=en
HTTP/1.0 302 Found
Location: HTTP::redirect https://10.131.131.120/test?ReceiptLocator=ABCDEF&CityOrigin=BOS&FirstName=John&LastName=Doe
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
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