[help] trying to understand why headers are not set properly
tx46 opened this issue · comments
tx46 commented
I'm far down a bug rabbit hole so I may have lost my mind already.
This is the request:
const url = "https://httpbin.org/post"
const json = await ky
.post(url, {
headers: { "x-test-header": "123", "user-agent": "foo-user", "accept": "anything test", "content-type": "foo" },
json: { myData: "12345" },
})
.json()
console.log(json)
Using httpbin to inspect sent headers. This is what I'm getting back (should be a reflection of the request sent):
{
args: {},
data: '{"myData":"12345"}',
files: {},
form: {},
headers: {
Accept: 'application/json',
'Accept-Encoding': 'br, gzip, deflate',
'Accept-Language': '*',
'Content-Length': '18',
'Content-Type': 'text/plain;charset=UTF-8',
Host: 'httpbin.org',
'Sec-Fetch-Mode': 'cors',
'User-Agent': 'node',
'X-Amzn-Trace-Id': ...
},
json: { myData: '12345' },
origin: ...,
url: 'https://httpbin.org/post'
}
Why are the headers not sent according to my request? What am I doing wrong? This is causing requests to an internal API to fail because the content-type is incorrect. I'm using Ky 1.1.0. Please help, losing my sanity quickly over this.
node --version ✔ 09:19:49
v20.8.1
Philip Arvidsson commented
duplicate of #535