Fortinet black logo

Cookie commands

Cookie commands

Part of the HTTP class, Cookie commands manipulate cookie operation:

HTTP:cookie_list() — Returns a list of cookies: their names and values.

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.

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

HTTP:cookie_list()

Returns a list of cookies: their names and values.

Syntax

HTTP:cookie_list();

Arguments

N/A

Example
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: 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.

Example
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: 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 HTTP_REQUEST.

Syntax

HTTP:cookie_crypto(t);

Arguments
Name Description

t

A table which specifies cookie name, parameter, action.

Example
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: HTTP_REQUEST / HTTP_RESPONSE

Cookie commands

Part of the HTTP class, Cookie commands manipulate cookie operation:

HTTP:cookie_list() — Returns a list of cookies: their names and values.

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.

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

HTTP:cookie_list()

Returns a list of cookies: their names and values.

Syntax

HTTP:cookie_list();

Arguments

N/A

Example
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: 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.

Example
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: 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 HTTP_REQUEST.

Syntax

HTTP:cookie_crypto(t);

Arguments
Name Description

t

A table which specifies cookie name, parameter, action.

Example
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: HTTP_REQUEST / HTTP_RESPONSE