PUT and POST are not passing headers

Because of our Tyk API Gateway configuration, I have to deconstruct the cookie that k6 stores, add quotes around it, and pass it back as a header. This works well in all cases… except this one.

Given this code:

response = http.get(`https://${tenant}.${environment}.${domain}/api/voice-settings-orchestration/phone-numbers/available`, {
        headers: {
            'Accept': '*/*',
            'Cookie': 'nextiva_sso="' + authToken + '"'
        },
        tags: { name: `${stepNum} - https://${tenant}.${environment}.${domain}/api/voice-settings-orchestration/phone-numbers/available` },
    });
    console.log(authToken)
    checkStatus(response, vuserID, iterNum, 200);
  


response = http.put(`https://${tenant}.${environment}.${domain}/api/voice-settings-orchestration/users/${profileId}/location/${locationId}`, {
       headers: {
           'Accept': '*/*',
           'Cookie': 'nextiva_sso="' + authToken + '"'
       },
       tags: { name: `${stepNum} - https://${tenant}.${environment}.${domain}/api/voice-settings-orchestration/users/<profileId>/location/<locationId>` },
   });
   console.log(authToken)
   checkStatus(response, vuserID, iterNum, 200);

The first one, the GET call, passes the cookie header; the second one, the PUT, does not. The second one also does not pass headers if I use POST.

This is bizarre - I know. Any help would be appreciated.

See the docs, params is the second parameter only in http.get(), it’s the third parameter in http.put(), http.post() and other shorthand methods, and actually the forth parameter in http.request(): k6/http

It’s a bit counter-intuitive, but unfortunately we can’t change this now, since it would be such a major breaking change… :disappointed: And since the second parameter of http.put() and http.post() is a body, and that can be an object, we can’t even show a warning or an error.

Hmm… Amazingly, I have written thousands of lines of code without noticing this. I’m not sure what this says about me.

So, if a PUT has no body payload (just url parameters), what is the right data to submit?

You can just use an empty string or null

1 Like