DataScripts execute when various events are triggered by data plane traffic. A single rule may execute different code during different events.
Many functions are only available within specific events. For instance, avi.http.redirect may only be used within an HTTP request event, whereas the avi.http.response may be used within the HTTP request or the HTTP response events.
Some functions, such as avi.http.method may be used in either the request or response events, even though the data returned is specifically from the client’s HTTP request.
Some DataScript functions may contain a context parameter, which means that while the function may be called during any event, it is grabbing data from an explicit event. Allowed values for a function’s context parameter are listed in its Knowledge Base article. Consider avi.http.get_header as an example. Executing it during an HTTP response event will return headers from the server’s response. However, by adding a
context parameter set to
avi.HTTP_REQUEST, headers from the client request may be retrieved and evaluated during the response event.
if avi.http.get_header("my_header", avi.HTTP_REQUEST) then avi.http.close_conn() end
While the DataScript above could be applied to either the HTTP request or response events, it is explicitly inspecting headers from the client’s request due to the optional context parameter.
- HTTP_REQ - This event triggers when all the headers of the HTTP request have been parsed successfully, but before any potential POST body has been received.
- HTTP_RESP - This event triggers when all headers of the HTTP response have been parsed successfully, but before the response body has been received.