DataScript: avi.http.response


Function avi.http.response (status, {headers}, body)


Responds to the HTTP request with a custom HTTP response.




status is used to specify the HTTP status code. See list for supported status codes below.

Optional headers are used to specify a table to add headers in the response. The default content-type used is “text/plain”. Hence if the body is some other mime-type such as “text/html”, the headers parameter should be used to specify the corresponding content-type.

Optional body flag is a string used to specify a custom HTTP response body.

To learn how to insert a graphic in a returned page, see Returning an Image from a DataScript.

Supported Status Codes

200 HTTP Ok
301 Moved Permanently
302 Found
303 See Other
307 Temporary Redirect
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
405 Method Not Allowed
413 Request Entity Too Large
414 Request-URI Too Long
429 Too Many Requests
451 Unavailable For Legal Reasons
501 Not Implemented
503 Service Unavailable


No return value


Prevent shell shock attack and notify the attacker with a friendly message.
local h = avi.http.get_headers()
for k, v in pairs(h) do
   if string.sub(v, 1, 2) == "()" and #v > 2 then
      avi.http.response(404, {content_type="text/html"},
      "Blocking Shellshock Attack!")