HTTP::path

Description

Returns or sets the path part of the HTTP request. The path is defined as the path and filename in a request. It does not include the query string.
For the following URL:
http://www.example.com:8080/main/index.jsp?user=test&login=check

The path is:
/main/index.jsp

Note that only ? is used as the separator for the query string. So, for the following URL:
http://www.example.com:8080/main/index.jsp;session_id=abcdefgh?user=test&login=check

the path is:
/main/index.jsp;session_id=abcdefgh

Syntax

HTTP::path [<string>]
HTTP::path -normalized [<string>]

HTTP::path [<string>]

  • Returns or sets the path part of the HTTP request. Rewriting the path will only affect the request to the pool member. The client will not see the update unless the web application uses the requested path to generate response headers and/or content. If you want the client to see the update to the path in the browser’s address bar, you can send an HTTP redirect using HTTP::redirect or HTTP::respond.

Note: AskF5 SOL9952 describes a defect in path parsing when the request includes an absolute URI in the Resource-URI field. You can find a link to the solution below in the Related Info section.

HTTP::path -normalized [<string>]

Returns or sets the path part of the HTTP request. Introduced in v12.1.0, the normalization of the path involves removing unnecessary directory traversals, conversion from microsoft style %uxxxx form to the standard %xx hex form, bytes not allowed in a uri are normalised to their percent-encoded representation, bytes percent-encoded when they don’t need to be are changed to their normal representation

Examples

Webmail redirect example: https://webmail.company.com is redirected to https://webmail.company.com/exchange. Redirected traffic then passes to the webmail pool.
when HTTP_REQUEST {
  if { [HTTP::path] equals "/" } {
    HTTP::redirect "/exchange/"
    #log local0. "redirect"
  } else {
    pool pool_webmail
    #log local0. "using pool "
  }
}

To set the path to lowercase, you can use the following example.
when HTTP_REQUEST {
  log local0. "\[HTTP::path\] original: [HTTP::path]"
  HTTP::path [string tolower [HTTP::path]]
}

Note: Due to a bug in v10.0 - 10.2.0, HTTP::path truncates the HTTP query string if present. The following rule can be used as a workaround. This is described in CR142756.
when HTTP_REQUEST {

   # Check if there is a query string
   if {[HTTP::query] eq ""}{

      # No query string, so set the entire URI to lower case
      HTTP::uri [string tolower [HTTP::uri]]

   } else {

      # Set the path to lower case and append the string to it
      HTTP::uri "[string tolower [HTTP::path]]?[HTTP::query]"
   }
}

You can use the BIG-IP as a primitive webserver. This uses a variable called $error_condition to decide to send an error page to the client, and a global class called $::logo_png_class. More information can be found on creating that class at: http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&forumid=5&postid=9523
when HTTP_REQUEST {
  if { $error_condition==1 } {
    # error condition was true, so respond back to client with html or image(s)
    switch [string tolower [HTTP::path]] {
      /image.png {
        HTTP::respond 200 content [b64decode [lindex $::logo_png_class]] "Content-Type" "image/png"}
      default {
        HTTP::respond 200 content "<html><title>Error</title><body>Error!<img src=/image.png></body></html>"}
    }
  }
}

Notes

  • Beginning in version 11, the cached behavior changes so that the value of the path is updated immediately after being set. Previously, you would need to log the value in a higher priority (read: higher number) of the current event or log the value in a later event in order to reflect the change.