Hi @franky, welcome to the forum
The behavior in k6 is a bit confusing, but I’ll try to explain below. Also make sure to read the cookies documentation to get a sense of how things work.
-
http.cookieJar()
(note lowercase c
) returns the reference to the cookie jar specific to the current VU. This is where you can inspect and set cookies for the VU without having to specify cookies on each request.
-
http.CookieJar()
(uppercase C
) is a constructor to create new local jars you can use to set cookies on each request, which would override the VU specific jar.
-
k6 doesn’t “generate” any cookies. It just sets them on the VU specific jar as returned by the server and then uses it for any subsequent requests.
In order to override cookies, you need to pass the URL as the first argument. So to empty (note: not delete!) the JSESSIONID
cookie you should do:
const jar = http.cookieJar(); // Get the VU specific jar
jar.set(urls.orderOrTicketLoader, 'JSESSIONID', null);
// Note that it's not required to pass the jar here
const res = http.post(urls.orderOrTicketLoader, JSON.stringify(otl));
This would send an empty string as JSESSIONID
, but not remove it from the Cookie
header. Depending on how your backend interprets this, this might be sufficient. Though I think this could be a k6 improvement, to delete the cookie from the header if it’s value is null
, and I’ll discuss it with the team.
If you want to remove all cookies from the request, calling jar.set(urls.orderOrTicketLoader, null, null)
on the per-VU cookie jar won’t work. This would instead send a blank cookie with a blank value, but not remove any of the other cookies.
If you want to do this, you’ll need to use a local cookie jar and pass it as a parameter on each request. For example this wouldn’t send a Cookie
header at all:
const jar = new http.CookieJar(); // Create a new local empty jar
const res = http.post(urls.orderOrTicketLoader, JSON.stringify(otl), { jar });
I suggest running the test with --http-debug=full
, or capturing the traffic with Wireshark if possible, to see the value of the Cookie
header.
Hope this helps,
Ivan