Header fetch
HTTP:headers()
Fetch all HTTP request or response headers. When it is called in client side, it returns all HTTP request headers; When it is called in server side, it returns all HTTP response headers.
Return: lua table of array.
for k, v in pairs(HTTP:headers()) do
for i = 1, #v do
debug("HEADER: %s[%d]: %s\n", k, i, v[i])
end
end
HTTP:header(“header-name”)
Fetch specific HTTP request or response header.
Return: lua array
for i, v in ipairs(HTTP:header(“set-cookie”)) do
debug(“set-cookie[%d]: %s\n”, i, v)
end
HTTP:cookies()
Fetch all cookies. When it is called in client side, it fetches “Cookies”; When it is called in server side, it fetches “Set-Cookie”.
Return: lua table containing only keys and values.
for k, v in pairs(HTTP:cookies()) do
debug("Cookie: %s = %s\n", k, v)
end
HTTP:cookie(“cookie-name”)
Fetch the value of specific cookies.
Return: string.
persist = HTTP:cookie(“persist”)
HTTP:args()
Fetch all arguments of HTTP query.
Return: lua table containing key and value.
for k, v in pairs(HTTP:args()) do
debug("ARG: %s = %s\n", k, v)
end
HTTP:arg(“arg-name”)
Fetch the value of specific arguments.
Return: string.
v = HTTP:arg(“ip”)
HTTP:host()
Return the string of HTTP request host.
HTTP:url()
Return the string of HTTP request URL. It is full URL including path and query.
HTTP:path()
Return the string of HTTP request path.
HTTP:method()
Return the string of HTTP request method.
HTTP:version()
Return the string of HTTP request or response version.
HTTP:status()
Return two strings including HTTP response status code and reason.
code, reason = HTTP:status()