Fortinet black logo

Cookie commands

Copy Link
Copy Doc ID 8173d994-aa85-11e9-81a4-00505692583a:893757
Download PDF

Cookie commands

HTTP:cookie_list()

Returns a list of cookies: their names and values.

Syntax

HTTP:cookie_list();

Arguments: N/A

Examples

when HTTP_REQUEST {

ret=HTTP:cookie_list()

for k,v in pairs(ret) do

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

end

}

FortiADC version: before V5.0

Used in events:

Used in HTTP_REQUEST / HTTP_RESPONSE

HTTP:cookie(t)

Allows you to GET/SET cookie value and cookie attribute, REMOVE a whole cookie, GET the whole cookie in HTTP RESPONSE, and INSERT a new cookie.

Syntax

HTTP:cookie(t);

t = {}

t[“name”] = “name”

t[“parameter”] = {can be value, cookie, path, domain, expires, secure, maxage, max-age, httponly, version, port, attrname }

t[“value”] = value

t[“case_sensitive”] = {0 or 1}

t[“action”] = {can be get, set, remove, insert}

ret = HTTP:cookie(t) --return is true if succeed or false if failed

Arguments

Name Description

t

A table which specifies cookie name, parameter, action.

Examples

when HTTP_REQUEST {

t={};

t["name"]="test"

t["parameter"]="value";--value, cookie, path, domain, expires, secure, maxage, max-age, httponly, version, port, attrname,

t["action"]="get"--get, set, remove, insert

ret = HTTP:cookie(t)

if ret then

debug("get cookie value succeed %s\n",ret);

else

debug("get cookie value failed\n");

end

}

Note:

name: specify cookie name

parameter: specify cookie value and attribute, including value, cookie, path, domain, expires, secure, maxage, max-age, httponly, version, port

action: can be get, set, remove, insert

FortiADC version: before V5.0

Used in events:

Used in HTTP_REQUEST / HTTP_RESPONSE

HTTP:cookie_crypto(t)

The provided function response_encrypt_cookie can be used to perform cookie encryption in HTTP RESPONSE and request_decrypt_cookie can be used to perform cookie decryption in HTP_REQUEST.

Syntax

HTTP:cookie_crypto(t);

Arguments

Name Description

t

A table which specifies cookie name, parameter, action.

Examples

when HTTP_REQUEST {

--encrypt cookie "test" in HTTP REQUEST before forwarding to real servers

local t={};

t["name"]="cookiename"

t["action"]="encrypt" --encrypt, or decrypt

t["key"]="0123456789ABCDEF";

t["prefix"]="XXXX";

t["size"]=size-- 128, 192, or 256, the corresponding key length is 16, 24, and 32

if HTTP:cookie_crypto(t) then

debug("Encrypt cookie succeed\n");

else

debug("Encrypt cookie failed\n");

end

}

Note:

  • name: specify cookie name
  • action: can be encrypt, or decrypt
  • Size: can be 128, 192, or 256, the corresponding key length is 16, 24, and 32

FortiADC version: before V5.2

Used in events:

Used in HTTP_REQUEST / HTTP_RESPONSE

Cookie commands

HTTP:cookie_list()

Returns a list of cookies: their names and values.

Syntax

HTTP:cookie_list();

Arguments: N/A

Examples

when HTTP_REQUEST {

ret=HTTP:cookie_list()

for k,v in pairs(ret) do

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

end

}

FortiADC version: before V5.0

Used in events:

Used in HTTP_REQUEST / HTTP_RESPONSE

HTTP:cookie(t)

Allows you to GET/SET cookie value and cookie attribute, REMOVE a whole cookie, GET the whole cookie in HTTP RESPONSE, and INSERT a new cookie.

Syntax

HTTP:cookie(t);

t = {}

t[“name”] = “name”

t[“parameter”] = {can be value, cookie, path, domain, expires, secure, maxage, max-age, httponly, version, port, attrname }

t[“value”] = value

t[“case_sensitive”] = {0 or 1}

t[“action”] = {can be get, set, remove, insert}

ret = HTTP:cookie(t) --return is true if succeed or false if failed

Arguments

Name Description

t

A table which specifies cookie name, parameter, action.

Examples

when HTTP_REQUEST {

t={};

t["name"]="test"

t["parameter"]="value";--value, cookie, path, domain, expires, secure, maxage, max-age, httponly, version, port, attrname,

t["action"]="get"--get, set, remove, insert

ret = HTTP:cookie(t)

if ret then

debug("get cookie value succeed %s\n",ret);

else

debug("get cookie value failed\n");

end

}

Note:

name: specify cookie name

parameter: specify cookie value and attribute, including value, cookie, path, domain, expires, secure, maxage, max-age, httponly, version, port

action: can be get, set, remove, insert

FortiADC version: before V5.0

Used in events:

Used in HTTP_REQUEST / HTTP_RESPONSE

HTTP:cookie_crypto(t)

The provided function response_encrypt_cookie can be used to perform cookie encryption in HTTP RESPONSE and request_decrypt_cookie can be used to perform cookie decryption in HTP_REQUEST.

Syntax

HTTP:cookie_crypto(t);

Arguments

Name Description

t

A table which specifies cookie name, parameter, action.

Examples

when HTTP_REQUEST {

--encrypt cookie "test" in HTTP REQUEST before forwarding to real servers

local t={};

t["name"]="cookiename"

t["action"]="encrypt" --encrypt, or decrypt

t["key"]="0123456789ABCDEF";

t["prefix"]="XXXX";

t["size"]=size-- 128, 192, or 256, the corresponding key length is 16, 24, and 32

if HTTP:cookie_crypto(t) then

debug("Encrypt cookie succeed\n");

else

debug("Encrypt cookie failed\n");

end

}

Note:

  • name: specify cookie name
  • action: can be encrypt, or decrypt
  • Size: can be 128, 192, or 256, the corresponding key length is 16, 24, and 32

FortiADC version: before V5.2

Used in events:

Used in HTTP_REQUEST / HTTP_RESPONSE