DataScript: avi.http.hostname

DataScript

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

Events HTTP_REQ
HTTP_RESP
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
   avi.http.close_conn()
end

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:
https://www.test.com/index.htm

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)
end

Note: This API is not supported in the events SSL_PRECONNECT, SSL_CLIENTHELLO, and SSL_HANDSHAKE_DONE.