Forum Discussion
Yozzer
Dec 13, 2010Nimbostratus
Search payload and redirect to payload value
Hi
I need some help with the irule below. I want to search for a POST data name 'Relay" and then check its value and then redirect the POST to the Relay value . Relay could have a few different values to redirect to. Any help would be great. Thanks
when RULE_INIT {
Default amount of request payload to collect (in bytes)
set static::collect_length 2048
}
when HTTP_REQUEST {
Only check POST requests
if {([HTTP::method] == "POST") && ([HTTP::uri] == "/test")} {
Check for a non-existent Content-Length header
if {[HTTP::header Content-Length] eq ""}{
Use default collect length of 1k for POSTs without a Content-Length header
set collect_length $static::collect_length
} elseif {[HTTP::header Content-Length] == 0}{
Don't try collect a payload if there isn't one
unset collect_length
} elseif {[HTTP::header Content-Length] > $static::collect_length}{
Use default collect length
set collect_length $static::collect_length
} else {
Collect the actual payload length
set collect_length [HTTP::header Content-Length]
}
If the POST Content-Length isn't 0, collect (a portion of) the payload
if {[info exists collect_length]}{
Trigger collection of the request payload
HTTP::collect $collect_length
}
}
}
when HTTP_REQUEST_DATA {
foreach p [split [HTTP::payload] &] {
set name [URI::decode [getfield $p = 1]]
set value [URI::decode [getfield $p = 2]]
if {[$name = "Relay" and $value contains "/test2/"]} {
HTTP::redirect "https://test.com/test2/login.aspx"
}
}
}
- hooleylistCirrostratusMaybe something like this?
when RULE_INIT { Default amount of request payload to collect (in bytes) set static::collect_length 2048 } when HTTP_REQUEST { Only check POST requests if {([HTTP::method] eq "POST") && ([HTTP::uri] eq "/test")} { Check for a non-existent Content-Length header if {[HTTP::header Content-Length] eq ""}{ Use default collect length of 1k for POSTs without a Content-Length header set collect_length $static::collect_length } elseif {[HTTP::header Content-Length] == 0}{ Don't try collect a payload if there isn't one unset collect_length } elseif {[HTTP::header Content-Length] > $static::collect_length}{ Use default collect length set collect_length $static::collect_length } else { Collect the actual payload length set collect_length [HTTP::header Content-Length] } If the POST Content-Length isn't 0, collect (a portion of) the payload if {[info exists collect_length]}{ Trigger collection of the request payload HTTP::collect $collect_length } } } when HTTP_REQUEST_DATA { set relay [URI::decode [URI::query "?[HTTP::payload]" Relay]] if {$relay ne ""}{ HTTP::redirect "https://test.com$relay" } }
- YozzerNimbostratusThanks Aaron,
- hooleylistCirrostratusThat would probably work, but this is a bit more efficient:
when HTTP_REQUEST_DATA { switch -glob [URI::decode [URI::query "?[HTTP::payload]" Relay]] { "*/test2/*" { HTTP::redirect "https://test.com/test2/login.aspx" } "*/test3/*" { HTTP::redirect "https://test.com/test3/login.aspx" } } }
- YozzerNimbostratusHi Aaron
- YozzerNimbostratus
- YozzerNimbostratusHi
- hooleylistCirrostratusCan you try the format from this Codeshare example?
- hooleylistCirrostratusA simpler option could be to append the payload to the redirect location. This assumes the client sends a URL encoded post data and the application accepts the parameters in the query string. It has the advantage of not looping through the parameters by name and not depending on Javascript.
when HTTP_REQUEST_DATA { switch -glob [URI::decode [URI::query "?[HTTP::payload]" Relay]] { "*/test2/*" { HTTP::redirect "https://test.com/test2/login.aspx?[HTTP::payload]" } "*/test3/*" { HTTP::redirect "https://test.com/test3/login.aspx?[HTTP::payload]" } } }
- YozzerNimbostratusThanks Aaron
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