|Function||avi.http.update_cookie( [context] )|
Modify the existing cookie attributes value in the HTTP response.
If the specified cookie("name") exists
|Parameter||name: The name of the cookie to be modified.
attr: attribute of an cookie("name") which has to be modified/added.
attr_val: value to be replaced with existing cookie attribute value.
path is the value (a string) of the path attribute
domain is the value (a string) of the domain attribute
expires is the value (an integer) of the expires attribute
maxage is the value (an integer) of the maxage attribute
httponly is the value (a boolean) of the httponly attribute
secure is the value (a boolean) of the secure attribute
samesite is the value (an integer) of the samesite attribute samesite attribute values : avi.http.Lax avi.http.None avi.http.Strict
|Example 1 - Modifying single Set-Cookie attribute:||Example of server sending a simple cookie with the name ‘name1’ and path as ‘/dummy’:
If you want to modify server cookie path to /dummy1 Data Script to modify the path attribute:
Set-Cookie will be modified to
|Example 2 - Adding and modifying Set-cookie attribute:||Example of server sending a simple cookie with the name ‘name2’ and path as ‘/dummy’:
If you want to update this server cookie with Domain to ‘www.avinetworks2.com’, HttpOnly and modify the path to ‘/dummy2’ with expiring in next 30 mins. Example of Data Script to add and modify cookie attributes:
Set-cookie will be modified to :
- avi.http.update_cookie() API doesn’t have any order for attributes.
- Max-Age cookie attribute can be modified/updated using avi.http.update_cookie().
- avi.http.update_cookie() API can be used to add individual/multiple attributes to an existing cookie.
- If avi.http.update_cookie() is called for the same cookie name multiple times, it can result in creating multiple Set-Cookie headers for the same cookie name. So, if multiple attributes for the same cookie need to be specified, please use the API to update multiple attributes in a single call as shown above.
- expires calculates from epoch start time 1st January, 1970. So if the user wants it to expire in 1 hr from the current time, they should use os.time + 3600 (as the units are in seconds).