DataScript: avi.http.get_header

DataScript

Function avi.http.get_header( [[name] [context]] )
Description Returns a table holding all the headers and their values as a key/value pair in a table. By default, the command will be executed against server response headers for an HTTP_RESP event, and against client request headers when executed within an HTTP_REQ event.
Events HTTP_REQ
HTTP_RESP
LB_DONE
Parameter If a name is not specified then a keyed table of all headers and corresponding values is returned. When a header is explicitly repeated, for instance, if there are multiple Set-Cookie headers, then the table contains a single key for the header with a value that is a table array.

If a name is specified, then only the value of the specified header is returned as a string. If the specified header is repeated, only the first header value is returned.

The context flag allows inspecting of header values from the avi.HTTP_REQUEST or avi.HTTP_RESPONSE events. For instance, during an HTTP_RESP event, the client request headers may be inspected.
Returns A table of headers and their values, or a string for a specific header value.
Example The following example can be used to prevent a Shell Shock attack. This attack embeds a client header which starts with () characters.
headers = avi.http.get_header()                -- get all the HTTP headers
for key,val in pairs(headers) do               -- iterate through all headers
   if #val > 2 and string.sub(val, 1, 2) == "()" then
      avi.http.close_conn()                    -- reset the TCP connection
   end
end