com.HTTPServiceRequest.setResponseCookies
Allows the server to return cookies to be set on the client application sending the request.
Syntax
setResponseCookies(
cookies WSHelper.WSServerCookiesType )
- cookies defines a dynamic array for
the cookies to be set. See WSHelper variables and records for more
information regarding
WSServerCookiesType
.
Usage
Allows the server to return cookies to be set on the client application sending the request.
A runtime error ( for example, -15566) may be raised if the cookies
sameSite
attribute is not set correctly. For instance, you can not set it to "None"
if secure is not set to TRUE
as well. This raises the error
"SameSite None value requires Secure to be set
".
In case of error, the method throws an exception and sets the
STATUS
variable. Depending on the error, a human-readable description of the
problem is available in the SQLCA.SQLERRM
register. See Error handling in GWS calls (STATUS).
Setting cookies example
IMPORT FGL WSHelper
DEFINE cookies WSHelper.WSServerCookiesType
# Set first cookie named 'CookieName'
LET cookies[1].name = "CookieName"
LET cookies[1].value = "AnyValue"
LET cookies[1].expires = now + INTERVAL (5) MINUTE TO MINUTE
LET cookies[1].secure = TRUE
LET cookies[1].sameSite = "Lax"
# Set second cookie named 'SecondCookie'
LET cookies[2].name = "SecondCookie
LET cookies[2].value = "AnotherValue"
# Set all cookies defined in the cookie array
CALL req.setResponseCookies(cookies)
CALL req.sendTextResponse(200, NULL, "Hello world")