Forum Discussion

uni's avatar
uni
Icon for Altostratus rankAltostratus
Feb 20, 2008

Different behaviour with HTTP::path and URI::path

I have noticed a difference in behaviour between the HTTP::path and URI::path commands.

I expected that [HTTP::path] would return the same result as [URI::path [HTTP::uri]], but HTTP::path includes the basename, whereas URI::path does not.

Given my rule below

rule test-rule {
   when HTTP_REQUEST {
      HTTP::respond 200 content "HTTP path [HTTP::path]\n URI path [URI::path [HTTP::uri]]\n\n"
   }
}

if I call it's virtual:

curl http://192.168.1.2/path/morepath/base.htm?query

I get the following response:

HTTP path /path/morepath/base.htm

URI path /path/morepath/

Do I misunderstand something here, or is this a bug? I'm running 9.3.0, so maybe this issue has been fixed.

5 Replies

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus
    Yes, the wiki documents this inconsistent behaviour.

     

    I suppose the question could be "Is it a bug, or just bad design?"
  • Since it's documented in the wiki as it behaves you can already consider it for not being a bug
  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus
    In the absence of any evidence to the contrary, it's bad design then.

     

     

    However, being documented in the wiki says nothing about it being by design. The wiki is not authoritative. From http://devcentral.f5.com/wiki/default.aspx/DevCentral.HomePage

     

    The DevCentral Wiki offers a location for F5 and users to contribute documentation, tips, samples, and other best practices for working with F5 products. While hosted through F5 DevCentral, this is not the official documentation for F5 products.
  • Maybe the naming convention isn't very intuitive, but it's very nice to have each of the three commands: HTTP::uri to get the full URI, HTTP::path to get the URI minus the query string, and URI::path to get the path without the object name or file extension. The commands haven't changed since they were introduced. So no, I don't think there are any bugs or issues with documentation. It's just not the most intuitive names.

    Aaron

    [edit: I just ran into an issue where I was trying to get the path for a URL that wasn't the one the client requested. I guess I see your point that it would be nice if URI::path $url returned just the path (ie, the URI minus the query string).

    Here is a bit of a hack to get the URI and the path for a static string (where you can't use HTTP::path or HTTP::uri):

    
       set url http://example.com/path/file.html?param=val
        Get the URI for a URL without using HTTP::uri (parses: /path/file.html?param=val)
       log local0. "URI: [getfield $url [URI::protocol $url]://[URI::host $url] 2]"
        Get the path for a URL without using HTTP::path (parses: /path/file.html)
       log local0. "path: [getfield [getfield $url [URI::protocol $url]://[URI::host $url] 2] "?" 1]"

    This might not be the most optimal solution, but it works...