You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently (v0.37.0) there's no way to delete a cookie from the CookieJar. Users can override a cookie by passing a local jar (http.CookieJar) or a cookies parameter per request, but there's no easy way of actually deleting a cookie from the Cookie header.
Setting the cookie on the VU jar to null actually sends it as an empty string:
importhttpfrom'k6/http';exportdefaultfunction(){http.get('https://httpbin.test.k6.io/cookies/set?one=1&two=2');constjar=http.cookieJar();// get the VU specific jarjar.set('https://httpbin.test.k6.io/cookies','one',null);constres=http.get('https://httpbin.test.k6.io/cookies');console.log(JSON.stringify(res.json().cookies));}
Similarly setting both the name and value to null (jar.set('https://httpbin.test.k6.io/cookies', null, null)) sends a new cookie with both empty values:
Setting a cookie to null with jar.set(url, 'cookie', null) could be a way to delete a specific cookie. If the user wanted to send an empty string they could just set the value to '' instead.
Similarly jar.set(url, null, null) could be used to delete all cookies for that URL, or jar.set(null, null, null) to delete all cookies in the jar.
A more intuitive approach suggested by @mstoykov would be to add another method, e.g. CookieJar.delete, to make this more explicit.
Already existing or connected issues / PRs (optional)
No response
The text was updated successfully, but these errors were encountered:
While looking at this issue, I would sometimes find it useful to be able to clear the cookie jar completely, but was unable to find a way to do that.
My use case would be where I want each iteration to use the same vuser, but on error with the site, fail() out of the iteration, clear all cookies when the iteration fails and login again, possibly with a new user id.
Feature Description
Currently (
v0.37.0
) there's no way to delete a cookie from theCookieJar
. Users can override a cookie by passing a local jar (http.CookieJar
) or acookies
parameter per request, but there's no easy way of actually deleting a cookie from theCookie
header.See this forum post for the use case.
Setting the cookie on the VU jar to
null
actually sends it as an empty string:Output
Similarly setting both the name and value to
null
(jar.set('https://httpbin.test.k6.io/cookies', null, null)
) sends a new cookie with both empty values:Output
Suggested Solution (optional)
Setting a cookie to
null
withjar.set(url, 'cookie', null)
could be a way to delete a specific cookie. If the user wanted to send an empty string they could just set the value to''
instead.Similarly
jar.set(url, null, null)
could be used to delete all cookies for that URL, orjar.set(null, null, null)
to delete all cookies in the jar.A more intuitive approach suggested by @mstoykov would be to add another method, e.g.
CookieJar.delete
, to make this more explicit.Already existing or connected issues / PRs (optional)
No response
The text was updated successfully, but these errors were encountered: