Fortinet white logo
Fortinet white logo

Handbook

Function

Functions

FortiADC supports the basic commands. If the user want more functions, the user can implement functions to define more with the basic commands.

Syntax

function function_name(parameter)

end

Examples: cookie command usage

FortiADC supports two cookie commands: cookie_list() and cookie(t) with t as a table input

when HTTP_REQUEST {

ret=HTTP:cookie_list()

for k,v in pairs(ret) do

debug("-----cookie name %s, value %s-----\n", k,v);

end

GET value of cookie "test"

value = get_cookie_value(HTTP, "test") --the return value is either boolean false or its value if exists.

debug("-----get cookie value return %s-----\n", value);

GET attribute path of cookie "test", can be used to get other attributes too

case_flag = 0; -- or 1

ret = get_cookie_attribute(HTTP, "test", "path", case_flag);--return value is either boolean false or its value if exists

debug("-----get cookie path return %s-----\n", ret);

SET value of cookie "test"

ret = set_cookie_value(HTTP, "test", "newvalue")--return value is boolean

debug("-----set cookie value return %s-----\n", ret);

REMOVE a whole cookie

ret = remove_whole_cookie(HTTP, "test")--return value is boolean

debug("-----remove cookie return %s-----\n", ret);

INSERT a new cookie.

Caution

You need to make sure the cookie was not first created by the GET command. Otherwise, by design FortiADC shall use SET command to change its value or attributes.

In HTTP REQUEST, use $Path, $Domain, $Port, $Version; in HTTP RESPONSE, use Path, Domain, Port, Version, etc.

ret = insert_cookie(HTTP, "test", "abc.d; $Path=/; $Domain=www.example.com, ")--return value is boolean

debug("-----insert cookie return %s-----\n", ret);

}

function get_cookie_value(HTTP, cookiename)

local t={};

t["name"]=cookiename

t["parameter"]="value";

t["action"]="get"

return HTTP:cookie(t)

end

attrname can be path, domain, expires, secure, maxage, max-age, httponly, version, port.

case_flag: If you use zero, FortiADC looks for default attributes named Path, Domain, Expires, Secure, Max-Age, HttpOnly, Version, Port. By setting this to 1, you can specify the case sensitive attribute name to look for in t["parameter"] which could be PAth, DOmaIn, MAX-AGE, EXpires, secuRE, HTTPONLy, VerSion, Port, etc.

function get_cookie_attribute(HTTP, cookiename, attrname, case_flag)

local t={};

t["name"]=cookiename

t["parameter"]=attrname;

t["case_sensitive"] = case_flag;

t["action"]="get"

return HTTP:cookie(t)

end

function set_cookie_value(HTTP, cookiename, newvalue)

local t={};

t["name"]=cookiename

t["value"]=newvalue

t["parameter"]="value";

t["action"]="set"

return HTTP:cookie(t)

end

function remove_whole_cookie(HTTP, cookiename)

local t={};

t["name"]=cookiename

t["parameter"]="cookie";

t["action"]="remove"

return HTTP:cookie(t)

end

function insert_cookie(HTTP, cookiename, value)

local t={};

t["name"]=cookiename

t["value"]=value;

t["parameter"]="cookie";

t["action"]="insert"

return HTTP:cookie(t)

end

Function

Functions

FortiADC supports the basic commands. If the user want more functions, the user can implement functions to define more with the basic commands.

Syntax

function function_name(parameter)

end

Examples: cookie command usage

FortiADC supports two cookie commands: cookie_list() and cookie(t) with t as a table input

when HTTP_REQUEST {

ret=HTTP:cookie_list()

for k,v in pairs(ret) do

debug("-----cookie name %s, value %s-----\n", k,v);

end

GET value of cookie "test"

value = get_cookie_value(HTTP, "test") --the return value is either boolean false or its value if exists.

debug("-----get cookie value return %s-----\n", value);

GET attribute path of cookie "test", can be used to get other attributes too

case_flag = 0; -- or 1

ret = get_cookie_attribute(HTTP, "test", "path", case_flag);--return value is either boolean false or its value if exists

debug("-----get cookie path return %s-----\n", ret);

SET value of cookie "test"

ret = set_cookie_value(HTTP, "test", "newvalue")--return value is boolean

debug("-----set cookie value return %s-----\n", ret);

REMOVE a whole cookie

ret = remove_whole_cookie(HTTP, "test")--return value is boolean

debug("-----remove cookie return %s-----\n", ret);

INSERT a new cookie.

Caution

You need to make sure the cookie was not first created by the GET command. Otherwise, by design FortiADC shall use SET command to change its value or attributes.

In HTTP REQUEST, use $Path, $Domain, $Port, $Version; in HTTP RESPONSE, use Path, Domain, Port, Version, etc.

ret = insert_cookie(HTTP, "test", "abc.d; $Path=/; $Domain=www.example.com, ")--return value is boolean

debug("-----insert cookie return %s-----\n", ret);

}

function get_cookie_value(HTTP, cookiename)

local t={};

t["name"]=cookiename

t["parameter"]="value";

t["action"]="get"

return HTTP:cookie(t)

end

attrname can be path, domain, expires, secure, maxage, max-age, httponly, version, port.

case_flag: If you use zero, FortiADC looks for default attributes named Path, Domain, Expires, Secure, Max-Age, HttpOnly, Version, Port. By setting this to 1, you can specify the case sensitive attribute name to look for in t["parameter"] which could be PAth, DOmaIn, MAX-AGE, EXpires, secuRE, HTTPONLy, VerSion, Port, etc.

function get_cookie_attribute(HTTP, cookiename, attrname, case_flag)

local t={};

t["name"]=cookiename

t["parameter"]=attrname;

t["case_sensitive"] = case_flag;

t["action"]="get"

return HTTP:cookie(t)

end

function set_cookie_value(HTTP, cookiename, newvalue)

local t={};

t["name"]=cookiename

t["value"]=newvalue

t["parameter"]="value";

t["action"]="set"

return HTTP:cookie(t)

end

function remove_whole_cookie(HTTP, cookiename)

local t={};

t["name"]=cookiename

t["parameter"]="cookie";

t["action"]="remove"

return HTTP:cookie(t)

end

function insert_cookie(HTTP, cookiename, value)

local t={};

t["name"]=cookiename

t["value"]=value;

t["parameter"]="cookie";

t["action"]="insert"

return HTTP:cookie(t)

end