Forum Discussion
How can I forward a http request to two different URL using iRules.
As per customer request, I need to forward a same http request to multiple (Two or Three) URL. Could someone please tell me whether iRules can meet this requirement or not?
If possible, please give some sample codes like below (maybe it’s wrong):
Sample 1:
when HTTP_REQUEST {
if { [HTTP::uri] contains "some tokens"} { HTTP::redirect http:// token.com 1. HTTP::redirect http:// token.com 2. } else { HTTP::redirect "http:// token.com" } }
Sample 2:
when HTTP_REQUEST {
if { [HTTP::uri] contains "some tokens"} { HTTP::uri "/newlocation1.jsp" HTTP::uri "/newlocation2.jsp" } else { HTTP::uri "/newlocation.jsp"
} }
Thanks a lot.
1 Reply
- R_Marc
Nimbostratus
So, to be clear, you want to just send a copy of the request to a second or third URL? Presumably to test new services before making them active?
The answer to that is a qualified yes. I am doing just that right now, specifically to test a new web service. For this, I had to create a "helper" virtual to handle the SSL for me. I capture the data, then play it to the helper virtual via a sideband connection (I pilfered bits from various examples on devcentral):
when RULE_INIT { set static::sb_vserver "helper-sideband-virtual" } when HTTP_REQUEST { Check if request was a POST if { [string tolower [HTTP::method]] eq "post" } { Connect to an external host with a connection timeout of 1000ms and an idle timeout of 30 seconds set conn [connect -timeout 1000 -idle 30 -status conn_status $static::sb_vserver] Check if connection was not established to sideband server if {$conn eq ""}{ return } Check if there is a Content-Length header if { [HTTP::header exists "Content-Length"] } { if { [HTTP::header "Content-Length"] > 1048000 }{ Content-Length over 1Mb so collect 1Mb set content_length 1048000 } else { Content-Length under 1Mb so collect actual length set content_length [HTTP::header "Content-Length"] } } else { set content_length 1048000 } Don't collect content if Content-Length header value was 0 if { $content_length > 0 } { HTTP::collect $content_length } } } when HTTP_REQUEST_DATA { Get the current connection status if { [string tolower [HTTP::method]] eq "post" } { set conn_info [connect info -idle -status $conn] if {$static::sb_debug} { log local0. "$log_prefix Connect info: <$conn_info>" } Send a TCP payload containing an HTTP request set data "POST /newservice HTTP/1.1\r\nUser-Agent: sideband/1.0\r\nContent-Type: application/xml; charset=utf-8\r\nHost: [HTTP::host]\r\nContent-Length: $content_length\r\n\r\n[HTTP::payload]" set send_info [send -timeout 3000 -status send_status $conn $data] close $conn } }If that's not what you are trying to do, please clarify.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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