Custom reply
These functions only can be used in HTTP client side event (only HTTP_REQUEST now).
HTTP:redirect (“fmt”, …)
Reply to client with redirect response.
HTTP:redirect(“https://%s”, HTTP:host())
HTTP:reply (response)
Reply to client with custom response.
Argument response is a lua array. It includes:
-
status: Integer. Default is 200.
-
reason: String. If not set, the system will use the default value of status code. For example, if the status code is 200, the default value of reason is “OK”.
-
headers: Lua table. Each value of the table is a lua array. It contains all headers except “content-length”. “content-length” will be automatically set with the body size.
-
Body: String.
HTTP:reply{
status = 400,
reason = “test reason”,
headers = {
["content-type"] = { "text/html" },
["cache-control"] = { "no-cache", "no-store" },
},
body = "<html><body><h1>invalid request<h1></body></html>",
}