minnoce944
Jul 30, 2014Nimbostratus
http rewrite and pool selection based on method
We have a requirement to perform URI rewrites for specific paths and direct that request to the appropriate pool. As an added bonus we also need to inspect the http method used to make sure we are sending to the appropriate pool.
I've came up with the following rule so far but getting a compile error error: /Common/irulename:10: error: [command is not valid in the current scope][if { [string tolower [HTTP::method]] eq "get" } {
Please help and also let me know if there is a better way to write this as i'm still learning irules.
first uri check to determine if it matches
method can be get or put, rewrite URI and route to appropriate pool
when HTTP_REQUEST {
if {( [string tolower [HTTP::uri]] eq "/IMSWeb/IMSServlet" ) } {
HTTP::uri "/ReservationService/IMSServlet"
pool pool1.tcp.8780
}
}
check to determine appropriate method, perform switch statement
if { [string tolower [HTTP::method]] eq "get" } {
method is get, need to rewrite URI and route to appropriate pool
switch -glob [string tolower [HTTP::uri] ] {
"/IMSWeb/rest/services/inventory" {
HTTP::uri "/ReservationService/IMSServlet"
pool pool1.tcp.8780
}
"/IMSWeb/Lookup" {
HTTP::uri "/ReservationService/UI/invLookUp"
pool pool1.tcp.8780
}
}
}
else { [string tolower [HTTP::method]] eq "put" } {
method is put, need to rewrite host & URI and route to appropriate pool
switch -glob [string tolower [HTTP::uri] ] {
"/IMSWeb/rest/services/item" {
HTTP::host "foo.com"
HTTP::uri "/iasserver/rest/services/item"
pool pool2.tcp.80
}
"/IMSWeb/rest/services/inventory" {
HTTP::host "foo.com"
HTTP::uri "/iasserver/rest/services/inventory"
pool pool2.tcp.80
}
}
}
}