Hi @adrianc137
Welcome to the support forum
I have tried reproducing the issue but was unfortunately unable to…
Here is the test script I’ve used:
import http from 'k6/http';
export default function () {
const request = {
method: 'POST',
url: 'https://httpbin.org/post',
body: JSON.stringify({ name: 'Bert' }),
params: {
headers: {
'Content-Type': 'application/json',
'custom-header-1': 'value1',
'custom-header-2': 'value2',
'Accept': 'application/json'
},
},
}
const responses = http.batch([request])
}
As you can see, the results are consistent with the request, and the headers are present accordingly:
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: http-batch-headers.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
INFO[0000] Request:
POST /post HTTP/1.1
Host: httpbin.org
User-Agent: k6/0.47.0 (https://k6.io/)
Content-Length: 15
Accept: application/json
Content-Type: application/json
Custom-Header-1: value1
Custom-Header-2: value2
Accept-Encoding: gzip
{"name":"Bert"} group= iter=0 request_id=7ed1feef-76b8-4065-7207-822de4abef81 scenario=default source=http-debug vu=1
INFO[0000] Response:
HTTP/2.0 200 OK
Content-Length: 524
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Tue, 31 Oct 2023 15:42:09 GMT
Server: gunicorn/19.9.0
{
"args": {},
"data": "{\"name\":\"Bert\"}",
"files": {},
"form": {},
"headers": {
"Accept": "application/json",
"Content-Length": "15",
"Content-Type": "application/json",
"Custom-Header-1": "value1",
"Custom-Header-2": "value2",
"Host": "httpbin.org",
"User-Agent": "k6/0.47.0 (https://k6.io/)",
"X-Amzn-Trace-Id": "Root=1-65412051-07e38fbb608cf2355393bdd5"
},
"json": {
"name": "Bert"
},
"origin": "79.213.171.33",
"url": "https://httpbin.org/post"
}
group= iter=0 request_id=7ed1feef-76b8-4065-7207-822de4abef81 scenario=default source=http-debug vu=1
So it does seem that k6 itself does what it advertises
To try and find the issue you’re experiencing, though, I would need to see a (dumbed-down, anonymized) somewhat more complete version of your script, if that’s possible. Especially one that gives me a good idea of how the body is passed, for instance.
Would you also be able to tell us which version of k6 you’re currently using?
Thank you