Comments (9)
This was caused by fd66cf0 which exposed the issue. Our only choice is to move towards private properties I think.
from undici.
just use Object.fromEntries
.
// Comment out this comment and have the latest undici installed just to verify it's still
// present in latest Undici, but for the test you can use the global Undici bundled in Node
// import { fetch } from "undici";
{
const baseHeaders = { "x-foo": "bar" };
const requestHeaders = new Headers({ "Content-Type": "application/json" });
const headers = {
...baseHeaders,
...Object.fromEntries(requestHeaders),
};
console.log("Result", headers);
await fetch("https://google.com", {
method: "POST",
headers,
});
}
from undici.
From a quick look at the behaviors in browsers, I think that the correct implementation is:
const baseHeaders = { "x-foo": "bar" };
const requestHeaders = new Headers({ "Content-Type": "application/json" });
const headers = {
...baseHeaders,
...Object.fromEntries(requestHeaders),
};
Note that the following does not work in browsers either:
const baseHeaders = { "x-foo": "bar" };
const requestHeaders = new Headers({ "Content-Type": "application/json" });
const headers = {
...baseHeaders,
...requestHeaders,
};
console.log("Result", headers);
It will result in not having Content-Type
in headers
object.
Having said that, I think it should not crash but works as expected & similarly to browsers.
@KhafraDev ping
from undici.
@mcollina, yeah, you are right. Headers instance itself won't spread, it will return an empty object. But neither will it throw, so that behavior is unexpected although useful as it lets the user know they aren't doing anything (the error is not hinting at that, though).
from undici.
Reported tangentially by MSW users as well.
from undici.
You are using the spread operator incorrectly.
In Headers
you need to use it with arrays, not objects.
from undici.
Yes I know I can do that, (and I did work around the issue in pingdotgg/uploadthing#813) - but that's working around the issue that the behavior changed in a minor Node.js release (havent tracked down what exact Undici release the behavior changed in)
from undici.
It will result in not having Content-Type in headers object
Oh wow I didnt even realize that. Was too focused looking at the Symbols xD
from undici.
Checked some other runtimes:
from undici.
Related Issues (20)
- MockAgent not compatible with ProxyAgent,EnvHttpProxyAgent,RetryAgent HOT 2
- I do not receive set-cookie in response.headers.getSetCookie() HOT 5
- Missing bytes() mixin in response.body from request method HOT 1
- how to use maxRedirections in fetch api HOT 1
- WebSocket Data Transfer Slows Down After Node.js 16.14.2 Release
- code error HOT 1
- Nightly tests are failing HOT 23
- ProxyAgent ignore & skip & rewrite "connect" parameter HOT 2
- socketPath option is not passed to the connect function HOT 15
- Release Notes empty HOT 1
- use real wpt test runner in CI
- `fetch` may try to use a closed connection HOT 6
- `UND_ERR_HEADERS_TIMEOUT` when changing system time during fetch HOT 3
- getting issue while running compodoc in angular project HOT 1
- WebSocket - Opening a connection to a non-existent server fire a error but keeps CONNECTING state indefinitely
- Add a proxy server example for testing undici fetch. HOT 2
- Undici fetch bypasses proxy (created with proxy npm package) HOT 2
- how to disable globaldispatcher? potential source of error in our unit tests HOT 1
- Readable stream not defined in CJS HOT 1
- Unable to access base `Event` properties from `CloseEvent`, `ErrorEvent` & `MessageEvent` for WebSocket HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from undici.