Cookie returned by K6 too short

So I’m trying to fetch a cookie from my site to be able to move forward with the test.

When I fetch it in k6, the cookie length is around 291 characters and my test can’t run.

However, when I use Postman to fetch it, I get a cookie at 1698 characters, and it runs fine.

I’ve been using the examples for logCookie and and logging headers in the documentation to pull them out, but no luck.

Here’s the relevant part of my script as it stands.

    const res = http.get("https://www.accolader.io/", {"responseType": "text"});
    for (var p in res.headers) {
    if (res.headers.hasOwnProperty(p)) {
        console.log(p + ' : ' + res.headers[p])
    }
}

Any ideas on what I should try next? Thanks!

Hi @trey_merkley,

I’ve tested this and I can’t reproduce it with httpbin. Maybe this is something to do with your server and it expecting some special header or something? Is the value cut at the end? the middle?

Any more information might help find out what actually happens but currently, it looks like an issue with your server :frowning:

Here is the script that I tested with and the result I got.

import http from "k6/http";
export default function main() {
    var cookieValue = "0123456789".repeat(250)
    var res = http.get("https://httpbin.test.k6.io/cookies/set/abcdefgh/"+ cookieValue,  {responseType: "text", redirects:0})
    for (var p in res.headers) {
        if (res.headers.hasOwnProperty(p)) {
            console.log(p + ' : ' + res.headers[p])
        }
    }
    var cookie = http.cookieJar().cookiesForURL("https://httpbin.test.k6.io/cookies/")["abcdefgh"][0]
    console.log(cookie)
    console.log(cookie.length)
    console.log(cookieValue.length)
    console.log(cookie == cookieValue)
}
INFO[0001] Date : Mon, 24 Aug 2020 08:19:39 GMT
INFO[0001] Content-Type : text/html; charset=utf-8
INFO[0001] Content-Length : 223
INFO[0001] Server : gunicorn/19.9.0
INFO[0001] Location : /cookies
INFO[0001] Set-Cookie : abcdefgh=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789; Path=/
INFO[0001] Access-Control-Allow-Origin : *
INFO[0001] Access-Control-Allow-Credentials : true
INFO[0001] 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
INFO[0001] 2500
INFO[0001] 2500
INFO[0001] true

Going up with the value breaks probably because of the limit on the URL not the actual max size of a cookie on either httpbin, nor k6 end ;).

The redirects:0 here is because the endpoint I hit both sets a cookie (given the provided values in the url’s path) and redirects to another page, which means I won’t be able to log the headers as you did.

I solved it, hehe, but what you said made me realize the issue. There were two cookies, and what I was getting I needed to pass back to the server to get it to return the cookie I actually needed. Thank you!