Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help] trying to understand why headers are not set properly #537

Closed
philiparvidsson opened this issue Oct 21, 2023 · 1 comment
Closed

Comments

@philiparvidsson
Copy link

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

@philiparvidsson
Copy link
Author

duplicate of #535

@sholladay sholladay closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants