Forum Discussion

Michael_Yates's avatar
Michael_Yates
Icon for Nimbostratus rankNimbostratus
Jan 22, 2008

HTTP Request rewrite before sending to specified node

I'm trying to make an iRule that will enable website testing on different specified nodes. Because most of the website that need to be testing in this way are URL dependent I wanted to do the testing by adding to the URL, and having the F5 remove the URL additions before sending the traffic to the specific node.

 

 

Something like this, but this doesn't rewrite the URL properly before sending the traffic to the node and fails with "node1" not found.

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/node1" } {

 

set newpath [findstr [HTTP::uri] "node1" 5]

 

node 192.168.1.1 8080

 

}

 

if { [HTTP::uri] starts_with "/node2" } {

 

set newpath [findstr [HTTP::uri] "node2" 5]

 

node 192.168.1.2 8080

 

} else {

 

pool $myPool

 

}

 

}

 

 

What I need is the following:

 

 

http://foo.website.com/node1

 

 

Then have the F5 strip out the "/node1" and send http://foo.website.com to the specified node.

 

 

Any help or is greatly appreciated.

2 Replies

  • If this is the method you want to try, below is a rule which should do it.

    I assume that requests the client sends will start with /node and then have the actual path the application expects following that node prefix. If the real path was /path/to/index.html, and you wanted to specify node1 received the request, you would make a request to /node1/path/to/index.html. The method below wouldn't work if you requested /node1path/to/index.html because the /node1 portion would be removed and the resulting URI wouldn't start with a leading forward slash.

    
    when HTTP_REQUEST {
       switch -glob [HTTP::path] {
          /node1/* {
              Remove the /node1 prefix from the path
             HTTP::path [string map {/node1 ""} [HTTP::path]]
              Set the node
             node 192.168.1.1 8080
          }
          /node2/* {
              Remove the /node1/ prefix from the path
             HTTP::path [string map {/node2 ""} [HTTP::path]]
              Set the node
             node 192.168.1.2 8080
          }
          default {
              Take some default action?
             pool http_pool
          }
       }
    }

    The iRule wiki and TCL man pages have details on the various commands:

    switch (Click here)

    HTTP::path (Click here)

    node (Click here)

    string map (Click here)

    Aaron
  • Just wanted to let everyone know that it worked.

     

     

    Thank you for the speedy response Hoolio, and for the Wiki links.