Forum Discussion

Nathan_McMahon_'s avatar
Nathan_McMahon_
Historic F5 Account
Feb 21, 2006

When to use HTTP::uri vs HTTP::path, contains vs matches

 

When should I be using the HTTP::uri versus the HTTP::path in an iRule? Second part of the question is should I be using a "contains" or "matches" for the following...

 

 

Sample uri, http://www.test.com/dir/page.php?=data

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "php" } {

 

pool php_pool

 

}

 

}

 

 

when HTTP_REQUEST {

 

if { [HTTP::path] contains ".php" } {

 

pool php_pool

 

}

 

}

 

 

If I want to do pool selection based on the content type, in this case it's a php, which would be the least cpu expensive route? Since the URI may not end with "php" would this need to be a contains or is there another method that is recommended?

 

 

Thanks in advance!

 

 

2 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    What I'd recommend doing is logging each one to see what data each returns, so you know which data set you actually want to work with.

    A simple rule like this would do the trick:

    
    when HTTP_REQUEST {
      log local0. "This is the HTTP URI [HTTP::uri]"
      log local0. "This is the HTTP Path [HTTP::path]"
    }

    In this case, you should find that while HTTP::uri returns the entire uri string following the hostname, HTTP::path returns only the "path" of the uri, up to the filename of the request, I.E. nothing after a "?" in the URI.

    So it sounds like, in your case, you'll want to use the HTTP::path.

    As to the question regarding contains, well, contains would cetainly work in this case, as it allows for the item you're searching for to occur anywhere within the string. It is, however, one of the least efficient search operators. Since we've determined that the HTTP::path variable will return a string that ends with the filname, it would be far more efficient to use that to your advantage and put the "ends_with" operator to use.

    Something like this, I would think:

    
    when HTTP_REQUEST {
      if { [HTTP::path] ends_with ".php" } {
        pool php_pool
      }
    }

    Hopefully that'll get you where you need to go.

    -Colin
  • Simply put, if you are calling the HTTP::path, you are simply asking the iRule to apply your "if statement" to the HTTP::uri in the http traffic up to where it sees a query sign .i.e "?" .

     

    In your case, http://www.test.com/dir/page.php?=data

     

    HTTP::path = /dir/page.php

     

    HTTP::uri = /dir/page.php?=data

     

    Whichever you choose, the operand in the "if statement" will apply on the HTTP:: content.

     

    when HTTP_REQUEST { if {[HTTP::uri] contains "php" } { pool php_pool } }

     

    OR

     

    when HTTP_REQUEST { if { [HTTP::path] contains ".php" } { pool php_pool } }

     

    Will give you the same result.

     

    I hope this helps :)