HTTP 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.
Syntax
HTTP:headers()
Arguments
N/A
Events
Applicable in HTTP_REQUEST and HTTP_RESPONSE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
when HTTP_REQUEST {
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.
Syntax
HTTP:header("header-name")
Arguments
|
Name |
Description |
|---|---|
|
header-name |
String type header name |
Events
Applicable in HTTP_REQUEST and HTTP_RESPONSE events.
Example
when HTTP_RESPONSE {
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”.
Syntax
HTTP:cookies()
Arguments
N/A
Events
Applicable in HTTP_REQUEST, HTTP_RESPONSE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
when HTTP_REQUEST {
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.
Syntax
HTTP:cookie(cookie-name)
Arguments
|
Name |
Description |
|---|---|
|
cookie-name |
String type cookie name |
Events
Applicable in HTTP_REQUEST, HTTP_RESPONSE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
when HTTP_REQUEST {
persist = HTTP:cookie("persist")
}
HTTP:args()
Fetch all arguments of HTTP query.
Syntax
HTTP:args()
Arguments
N/A
Events
Applicable in HTTP_REQUEST, HTTP_RESPONSE and HTTP_DATA_REQUEST
Example
when HTTP_REQUEST {
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.
Syntax
HTTP:arg(arg-name)
Arguments
|
Name |
Description |
|---|---|
|
arg-name |
String type argument name |
Events
Applicable in HTTP_REQUEST, HTTP_RESPONSE and HTTP_DATA_REQUEST
Example
when HTTP_REQUEST {
v = HTTP:arg("ip")
}
HTTP:host()
Return the string of HTTP request host.
Syntax
HTTP:host()
Arguments
N/A
Events
Applicable in HTTP_REQUEST and HTTP_RESPONSE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
when HTTP_REQUEST {
local host = HTTP:host()
if host == "www.example.com" then
debug("host = %s", host)
end
}
Output: www.example.com
HTTP:url()
Return the string of HTTP request URL. It is the full URL including path and query.
Syntax
HTTP:url()
Arguments
N/A
Events
Applicable in HTTP_REQUEST, HTTP_RESPOSNE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
For instance, request url: http://www.example.com/test.html?id=1234
when HTTP_REQUEST {
local url = HTTP:url()
if url == "/test.html?id=1234" then
debug("url = %s", url)
end
}
Output: url = /test.html?id=1234
HTTP:path()
Return the string of the HTTP request path.
Syntax
HTTP:path()
Arguments
N/A
Events
Applicable in HTTP_REQUEST, HTTP_RESPOSNE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
For instance, request url: http://www.example.com/test.html?id=1234
when HTTP_REQUEST {
local path = HTTP:path()
if path == "/test.html" then
debug("path = %s", path)
end
}
Output: path = /test.html
HTTP:method()
Return the string of HTTP request method.
Syntax
HTTP:method()
Arguments
N/A
Events
Applicable in HTTP_REQUEST, HTTP_RESPOSNE, HTTP_DATA_REQUEST and HTTP_DATA_RESPONSE
Example
when HTTP_REQUEST {
local method = HTTP:method()
debug("method = %s", method)
if method == "GET" then
debug("method = %s", method)
end
}
Output: method = GET
HTTP:status()
Return two strings including HTTP response status code and reason.
code, reason = HTTP:status()
Syntax
HTTP:status()
Arguments
N/A
Events
Applicable in HTTP_RESPONSE and HTTP_DATA_RESPONSE
Example
when HTTP_RESPONSE {
code, reason = HTTP:status()
if code == "200" then
debug("code = 200, reason = %s", reason)
end
}
Output: code = 200, reason = OK