DataScript: Object Model
DataScripts are attached to virtual services. Each DataScript will run when an event is triggered, such as when an HTTP request or HTTP response is received by the virtual service. Each DataScript objects will include at least one, and potentially more events.
A virtual service may have multiple DataScripts attached. If multiple DataScripts use the same events, such as HTTP request, then the order of the DataScripts assigned to the virtual service will be taken into account for the order of processing of the DataScripts. For instance, if the first DataScript is set to discard all client requests to the /secure
directory, and the second DataScript is set to redirect all authenticated clients making requests for the /secure
directory to a different path, the second DataScript will never be run.
The supported events are:
- HTTP_REQ — This event triggers when the request line and 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 the response status line and all headers of the HTTP response have been parsed successfully, but before the response body has been received.
- RESP_FAILED — This event is added with Avi Vantage 17.1.3. It triggers when any error/timeout happens before a valid response header can be received from the server and forwarded to the client. There are only 3 HTTP functions which can be invoked from the RESP_FAILED event:
- avi.http.response()
- avi.http.redirect()
- avi.http.internal_status()
All other HTTP functions return ERROR and the client connection will end prematurely.
Examples under which the RESP_FAILED event occurs include: - TCP/SSL connection/handshake to back-end server fails
- Request proxy/send to back-end server times out
- No Response or partial Response Headers or Bad Response Headers from server
- Server resets connection while Avi is waiting for the back-end server to respond
-
LB_DONE: Starting with Avi Vantage release 18.2.3, LB_DONE event is supported. This event triggers once the server selection is done, but before establishing the connection to the back-end server. This event enables the configuration of various policies once the server selection is done.
The following are the DataScripts APIs supported for this event:
This object model allows the flexibility to create a library of DataScripts. A virtual service can be configured to refer to any DataScript object from this library, provided it is of the same protocol as the DataScript’s events. To use a DataScript with an HTTP request event, the virtual service must be configured for application type HTTP. Each virtual service object can refer to any number of DataScripts. All DataScripts are parsed during configuration time. Hence, any incorrect DataScript will result in a failure when the user attempts to save the new or modified DataScript. The configuration time error is reported as an aid in debugging. When a DataScript implementation encounters a failure, the script implementation ends prematurely for that HTTP request or response. An HTTP Internal Server Error is sent to the client and a client log is generated with the stack trace of the prematurely ended script to aid in debugging.