oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.09k stars 2.47k forks source link

allow user-defined `Content-Length` passed to `fetch` to override default one #10905

Closed nektro closed 1 week ago

nektro commented 1 week ago

another case caught by running axios tests

github-actions[bot] commented 1 week ago

❌ @nektro, your commit has failing tests :(

ο£ΏπŸ’ͺ 4 failing tests Darwin AARCH64

ο£ΏπŸ’» 3 failing tests Darwin x64 baseline

ο£ΏπŸ’» 2 failing tests Darwin x64

🐧πŸ’ͺ 1 failing tests Linux AARCH64

🐧πŸ–₯ 1 failing tests Linux x64 baseline

🐧πŸ–₯ 1 failing tests Linux x64

πŸͺŸπŸ’» 9 failing tests Windows x64 baseline

πŸͺŸπŸ’» 9 failing tests Windows x64

View logs

Jarred-Sumner commented 1 week ago

undici-fetch, in Node.js:

> fetch("https://www.toptal.com/developers/postbin/1715151383763-3950115528423", { body: "123", headers: { "Content-Length": "2048" }, method: "POST" })
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 148,
  [Symbol(trigger_async_id_symbol)]: 121
}
> Uncaught [TypeError: fetch failed] {
  [cause]: RequestContentLengthMismatchError: Request body length does not match content-length header
      at AsyncWriter.end (node:internal/deps/undici/undici:8088:19)
      at writeIterable (node:internal/deps/undici/undici:7992:16) {
    code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
  }
}

I don't think we should make this change in the HTTP client itself. I think if we want to allow users to override Content-Length via node:http, we should have some other mechanism for doing so which does not percolate up to the global fetch API