Does K6 supports custom content-type? Custom content-type changes to application/json during execution

I am sending a POST request and I send custom content-type in headers. My request fails with
{
“code” : 400,
“message” : “Unable to process JSON”
}
On checking the error it seems like the content-type is correct. Then I added --http-debug=“full” to my k6 command. the debugging information shows that content-type is application/json.

Does K6 supports custom content-type?

Yes, k6 supports custom content-type. Can you share your code, the call should be in the format http.port(url, body, {headers: {'content-type': whatever}}.

export default function (data) {
  let proofId;
    const requestBody = JSON.stringify({
      "facts": [
        {
          "==": ["source_hash", "3ad3031f5503a5504af825262ee8232cc04d4ea6683d42c5ee0a2f2a27ac9824"]
        },
        {
          "==": ["mime", "text/plain"]
        },
        {
          "==": ["size", 5]
        },
        {
          "==": ["receiver", 1000]
        },
        {
          "==": ["creation_time", 1598322122]
        }
      ]
    });
    const headers = {
      headers: {
        'Authorization': `Bearer ${data[0]}`,
        'Content-Type': 'application/cnd.proof-v2+json',
      },
    };
    projectId = data[1][Math.floor(Math.random() * maxUsers)];
    res = http.post(`https://${env}.dbx.cxl.io/api/proofworks/projects/${projectId}/proofs`, requestBody, headers);
    check(res, {
      'Create Proof: is status 201': (r) => r.status == 201,
    });
}

I am not sure what the issue is, but it seems to be on the side of your backed? I modified your script slightly to point it to httpbin.org:

import http from 'k6/http';

export default function (data) {
    const requestBody = JSON.stringify({
        "facts": [
            {
                "==": ["source_hash", "3ad3031f5503a5504af825262ee8232cc04d4ea6683d42c5ee0a2f2a27ac9824"]
            },
            {
                "==": ["mime", "text/plain"]
            },
            {
                "==": ["size", 5]
            },
            {
                "==": ["receiver", 1000]
            },
            {
                "==": ["creation_time", 1598322122]
            }
        ]
    });
    const headers = {
        headers: {
            'Authorization': `Bearer some-token`,
            'Content-Type': 'application/cnd.proof-v2+json',
        },
    };
    let res = http.post(`https://httpbin.org/anything/123/proofs`, requestBody, headers);

    console.log(res.body);
}

and the result I get is

{
  "args": {}, 
  "data": "{\"facts\":[{\"==\":[\"source_hash\",\"3ad3031f5503a5504af825262ee8232cc04d4ea6683d42c5ee0a2f2a27ac9824\"]},{\"==\":[\"mime\",\"text/plain\"]},{\"==\":[\"size\",5]},{\"==\":[\"receiver\",1000]},{\"==\":[\"creation_time\",1598322122]}]}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Authorization": "Bearer some-token", 
    "Content-Length": "209", 
    "Content-Type": "application/cnd.proof-v2+json", 
    "Host": "httpbin.org", 
    "User-Agent": "k6/0.30.0 (https://k6.io/)", 
    "X-Amzn-Trace-Id": "Root=1-600eb362-16fbfabf2990ed892d3c47fd"
  }, 
  "json": {
    "facts": [
      {
        "==": [
          "source_hash", 
          "3ad3031f5503a5504af825262ee8232cc04d4ea6683d42c5ee0a2f2a27ac9824"
        ]
      }, 
      {
        "==": [
          "mime", 
          "text/plain"
        ]
      }, 
      {
        "==": [
          "size", 
          5
        ]
      }, 
      {
        "==": [
          "receiver", 
          1000
        ]
      }, 
      {
        "==": [
          "creation_time", 
          1598322122
        ]
      }
    ]
  }, 
  "method": "POST", 
  "origin": "88.203.157.59", 
  "url": "https://httpbin.org/anything/123/proofs"
}

See "Content-Type": "application/cnd.proof-v2+json", the server received the correct value from k6 :man_shrugging:

@ned I am doubtful about it being a backend problem. This request works perfectly fine from postman. I’ll have to look around a bit i guess