Forum Discussion

Dachicourt_Fabi's avatar
Dachicourt_Fabi
Icon for Nimbostratus rankNimbostratus
Jan 07, 2005

Using format strings in version 9

the string %h %p et %u don't work on version 9

 

 

for exemple, a rule like

 

 

rule my_rule {

 

if ([HTTP::uri] ends_with "baz") {

 

redirect to "https://%h:8080/%u/"

 

}

 

else {

 

use pool web_pool

 

}

 

}

 

 

don't work anymore.

 

Do you know a way to do this in version 9 ?
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    These special format strings were dropped because it would require unnecessary changes to the native Tcl processing. Instead, simply use the '[' ']' evaluation and the appropriate F5 Tcl command. Here's what your rule would look like:

     
     rule my_rule {  
        when HTTP_REQUEST { 
           if { [HTTP::uri] ends_with "baz" } {  
              redirect to "https://[HTTP::host]:8080/[HTTP::uri]/"  
           }  
           else {  
              use pool web_pool  
           } 
        } 
     } 
     

  • For those interested, the F5 TCL commands are documented in the user manual as well as in the Docs and Tips section of DevCentral. The tip on "Querying Header and Content Data" can be found here:

     

     

    http://devcentral.f5.com/Default.aspx?TabID=29&newsType=ArticleView&articleId=32

     

     

    -Joe
  • Joe,

    Based on the doc you listed, I constructed the following rule:

     
     when HTTP_REQUEST {  
         redirect to "https://[URI::host][HTTP::uri]" 
     } 
     

    That gave me a syntax error. I played around and came up with this:

     
     when HTTP_REQUEST {  
         redirect to "https://[HTTP::host][HTTP::uri]" 
     }

    Are the URI::xxx commands listed valid? Or am I just using them incorrectly?

    Thanks,

    Brian
  • drteeth_127330's avatar
    drteeth_127330
    Historic F5 Account
    The URI commands can be used to extract individual field components from a URI. For example,
    [URI::query [HTTP::uri]]
    should be equivalent to
    [HTTP::query]
    However, the protocol, host, and port commands are only meaningful when used with a full URI, e.g. http://www.foo.com/bar.html. This is the problem that you encountered.

  • bl0ndie_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    HTTP::uri returns the URI that is sent on the GET/POST request. This normally means that it will not have the protocol or host strings, at least not in the same way the user may have typed into the user agent. The exception being proxy requests, which will have the full URI.

    We added bunch of utility of functions that make the URI parsing easy, please see below for the brief explanations. One thing to note though, after a long discussion with rapMaster_c, drTeeth, unRuly (last names omitted as a professional courtesy), we decided to chose ‘URI::path’ to carry the spirit of UNIX where you need to use ‘basename’ and path to get the actual document. There is a good example of this on one of my earlier postings for making BigIP behave like an http proxy. Here is the link to the posting … http://devcentral.f5.com/default.aspx?tabid=28&view=topic&forumid=5&postid=1332

      URI::protocol Extracts the protocol part from the URI string that you specify.    
        URI::basename Extracts the basename part from the URI string that you specify.    
        URI::path Extracts the path from the URI string that you specify.    
        URI::query Extracts the query part from the URI string that you specify.    
        URI::host Extracts the host part from the URI string that you specify.    
        URI::compare Compares URIs as recommended by RFC 2616 section 3.2.3.    
        URI::decode Returns the decoded URI string.    
        URI::encode Returns the encoded URI string    
        URI::port Extracts the port part from the URI string that you specify.

  • One thing that confused me is your terminology. In "web" terminolgy I thought a URL consisted of protocol://hostname:port/uri

     

     

    It seems you use the term URI consistently to refer to a URL. In your terminology a URI consists of protocol://basename:port/path?query vs just path?query

     

     

    Is my understanding of your terminology correct?

     

     

    Thanks,

     

    Brian
  • rapmaster_c_127's avatar
    rapmaster_c_127
    Historic F5 Account
    I'm not sure I agree with you. Here's a website that sums up our take on URI vs URL vs URN.

     

     

    http://www.pierobon.org/iis/url.htm

     

     

  • Loc_Pham_101863's avatar
    Loc_Pham_101863
    Historic F5 Account
    Further clarifications/recommendations by W3C on URI vs. URL vs. URN. Note the Contemporary View.

     

    http://www.w3.org/TR/uri-clarification/

     

    Loc