Forum Discussion
Kaloyan
Cirrus
Oct 19, 2017iRule pointing traffic from one pool member to another with HTTP::retry
Hi,
I have the following traffic path:
Client request -> External VIP ->pool with member with IP:port of internal VIP -> Internal VIP -> Pool with one member, which respond always with 307 redirect t...
Kaloyan
Cirrus
Oct 19, 2017Here is the iRule:
when CLIENT_ACCEPTED {
set server 0
set retried 0
set default_pool [LB::server pool]
}
when HTTP_REQUEST {
set clientip ""
if { [HTTP::header exists "X-Forwarded-For"] } {
set clientip [lindex [ split [lindex [HTTP::header values X-Forwarded-For] 0] "," ] 0]
} else {
set clientip [IP::client_addr]
}
log local0. "persist lookup on REQUEST: $clientip"
if { [HTTP::cookie exists test1] } {
pool test_1
persist cookie insert test1 0
log local0. "FROM_ifcheck_cookie_exist_HDLtest1 HTTP request: [HTTP::request]"
}
elseif { [HTTP::cookie exists test2] } {
pool test_2
persist cookie insert test2 0
log local0. "FROM_ifcheck_cookie_exist_HDLtest2 HTTP request: [HTTP::request]"
}
elseif { ($retried == 0) } {
set request_headers [HTTP::request]
Set payload content legth to capture.
if {[HTTP::header exists "Content-Length"] && [HTTP::header "Content-Length"] <= 4000000}{
set content_length [HTTP::header "Content-Length"]
}
else {
set content_length 4000000
}
Capture HTTP payload from request, HTTP::collect triggers event HTTP_REQUEST_DATA
if { [info exists content_length] && $content_length > 0} {
HTTP::collect $content_length
}
pool $default_pool
persist none
}
elseif { ($retried == 1) } {
Check DGL external-ip-check for IP/X-Forwarded-For match and assign uie persistence
if {[class match $clientip equals "external-ip-check"]} {
switch -glob $server {
"1" {
pool test_1
persist uie $clientip 1800
log local0. "FROM_retried_check_SP_test1 HTTP request: [HTTP::request]"
}
"2" {
pool test_2
persist uie $clientip 1800
log local0. "FROM_retried_check_SP_test2 HTTP request: [HTTP::request]"
}
default {
log local0. "Configuration needed for HTTP_REQUEST. HTTP request: [HTTP::request]"
}
}
} else {
switch -glob $server {
"1" {
pool test_1
persist cookie insert test1 0
log local0. "FROM_retried_check_with_cookie_test1 HTTP request: [HTTP::request]"
}
"2" {
pool test_2
persist cookie insert test2 0
log local0. "FROM_retried_check_with_cookie_test2 HTTP request: [HTTP::request]"
}
default {
log local0. "Configuration needed for HTTP_REQUEST. HTTP request: [HTTP::request]"
}
}
}
}
}
when HTTP_REQUEST_DATA {
Set payload, depends on HTTP::collect done in HTTP_REQUEST event.
set payload [HTTP::payload]
Append HTTP payload to HTTP request header to form a complete HTTP post request (request + payload)
append request_headers [HTTP::payload [HTTP::payload length]]
}
when HTTP_RESPONSE {
if { ([HTTP::status] == 307) } {
log local0. "HTTP_RESPONSE from Dispatcher: [HTTP::header Location] for HTTP request: $request_headers"
set retried 1
switch -glob [string tolower [HTTP::header Location]] {
"*:first/*"
{
set server 1
HTTP::retry "$request_headers"
}
"*:second/*"
{
set server 2
HTTP::retry "$request_headers"
}
default {
set server 0
log local0. "Configuration needed for HTTP_RESPONSE. New location from Dispatcher: [HTTP::header Location] for HTTP request: $request_headers"
}
}
}
else {
log local0. "HTTP_RESPONSE from APP-server: [HTTP::response]"
}
}
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