DataScript: avi.http.hostname

Function avi.http.hostname()
Description Returns the host name from the request. This field could be learned from the following sources, in the following order of precedence:

  • Host name from the request line
  • Host name from the ‘Host’ request header field
  • The server name matching a request

NOTE: Host name does not include the port, even in case of a request line or host header of the form hostname:port

Parameter None
Returns String of the hostname requested by the client. It does not include the port.
Example 1 If there is no host name, close the TCP connection.

host = avi.http.hostname()
if not host then

Example 2 Rewrite the location header for relative redirects to absolute, while changing them to HTTPS. This DataScript should be applied to the HTTP Response event.

The rewritten headers should look like:

loc = avi.http.get_header("Location")
if loc and string.beginswith(loc, "/") then
   loc = "https://" .. avi.http.hostname() .. loc
   avi.http.replace_header("Location", loc)

Updated: 2018-01-22 22:44:46 +0000