Fortinet white logo
Fortinet white logo
8.0.0

Header fetch

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 arrays.

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.

Return: lua array.

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”.

Return: lua table containing only keys and values.

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.

Return: string.

Example
when HTTP_REQUEST {
    persist = HTTP:cookie("persist")
}

HTTP:args()

Fetch all arguments of HTTP query.

Return: lua table containing key and value.

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.

Return: string.

Example
when HTTP_REQUEST {
    v = HTTP:arg("ip")
}

HTTP:host()

Return the string of HTTP request host.

Example

Request : http://www.example.com/test.html?id=1234

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.

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.

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.

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:version()

Return the string of HTTP request or response version.

Example
when HTTP_RESPONSE {
    debug("http version = %s", HTTP:version())
}

Output: http version = 1.1

HTTP:status()

Return two strings including HTTP response status code and reason.

code, reason = HTTP:status()

Example
when HTTP_RESPONSE {
    code, reason = HTTP:status()
    if code == "200" then
        debug("code = 200, reason = %s", reason)
    end
}

Output: code = 200, reason = OK

Header fetch

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 arrays.

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.

Return: lua array.

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”.

Return: lua table containing only keys and values.

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.

Return: string.

Example
when HTTP_REQUEST {
    persist = HTTP:cookie("persist")
}

HTTP:args()

Fetch all arguments of HTTP query.

Return: lua table containing key and value.

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.

Return: string.

Example
when HTTP_REQUEST {
    v = HTTP:arg("ip")
}

HTTP:host()

Return the string of HTTP request host.

Example

Request : http://www.example.com/test.html?id=1234

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.

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.

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.

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:version()

Return the string of HTTP request or response version.

Example
when HTTP_RESPONSE {
    debug("http version = %s", HTTP:version())
}

Output: http version = 1.1

HTTP:status()

Return two strings including HTTP response status code and reason.

code, reason = HTTP:status()

Example
when HTTP_RESPONSE {
    code, reason = HTTP:status()
    if code == "200" then
        debug("code = 200, reason = %s", reason)
    end
}

Output: code = 200, reason = OK