@whatwg-node/node-fetch 0.7.20-alpha-20250515124418-2db9e75f23af1518924d027ea553d45f492c54f9 → 0.7.20-alpha-20250515130141-273de2d136d7ccbd40240112221a1f02b9ac5bb7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/Headers.js +9 -12
- package/cjs/Response.js +2 -1
- package/cjs/utils.js +4 -0
- package/esm/Headers.js +9 -12
- package/esm/Response.js +2 -1
- package/esm/utils.js +3 -0
- package/package.json +1 -1
- package/typings/utils.d.cts +1 -0
- package/typings/utils.d.ts +1 -0
package/cjs/Headers.js
CHANGED
@@ -4,6 +4,7 @@ exports.PonyfillHeaders = void 0;
|
|
4
4
|
exports.isHeadersLike = isHeadersLike;
|
5
5
|
const node_util_1 = require("node:util");
|
6
6
|
const IteratorObject_js_1 = require("./IteratorObject.js");
|
7
|
+
const utils_js_1 = require("./utils.js");
|
7
8
|
function isHeadersLike(headers) {
|
8
9
|
return headers?.get && headers?.forEach;
|
9
10
|
}
|
@@ -30,7 +31,7 @@ class PonyfillHeaders {
|
|
30
31
|
if (this.headersInit == null) {
|
31
32
|
return null;
|
32
33
|
}
|
33
|
-
if (
|
34
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
34
35
|
const found = this.headersInit.filter(([headerKey]) => headerKey.toLowerCase() === normalized);
|
35
36
|
if (found.length === 0) {
|
36
37
|
return null;
|
@@ -68,7 +69,7 @@ class PonyfillHeaders {
|
|
68
69
|
if (!this._map) {
|
69
70
|
this._setCookies = [];
|
70
71
|
if (this.headersInit != null) {
|
71
|
-
if (
|
72
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
72
73
|
this._map = new Map();
|
73
74
|
for (const [key, value] of this.headersInit) {
|
74
75
|
const normalizedKey = key.toLowerCase();
|
@@ -142,12 +143,8 @@ class PonyfillHeaders {
|
|
142
143
|
this._setCookies = [value];
|
143
144
|
return;
|
144
145
|
}
|
145
|
-
if (this._map) {
|
146
|
-
|
147
|
-
return;
|
148
|
-
}
|
149
|
-
if (this.headersInit != null) {
|
150
|
-
if (Array.isArray(this.headersInit)) {
|
146
|
+
if (!this._map && this.headersInit != null) {
|
147
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
151
148
|
const found = this.headersInit.find(([headerKey]) => headerKey.toLowerCase() === key);
|
152
149
|
if (found) {
|
153
150
|
found[1] = value;
|
@@ -182,7 +179,7 @@ class PonyfillHeaders {
|
|
182
179
|
});
|
183
180
|
if (!this._map) {
|
184
181
|
if (this.headersInit) {
|
185
|
-
if (
|
182
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
186
183
|
this.headersInit.forEach(([key, value]) => {
|
187
184
|
callback(value, key, this);
|
188
185
|
});
|
@@ -210,7 +207,7 @@ class PonyfillHeaders {
|
|
210
207
|
}
|
211
208
|
if (!this._map) {
|
212
209
|
if (this.headersInit) {
|
213
|
-
if (
|
210
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
214
211
|
yield* this.headersInit.map(([key]) => key)[Symbol.iterator]();
|
215
212
|
return;
|
216
213
|
}
|
@@ -233,7 +230,7 @@ class PonyfillHeaders {
|
|
233
230
|
}
|
234
231
|
if (!this._map) {
|
235
232
|
if (this.headersInit) {
|
236
|
-
if (
|
233
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
237
234
|
yield* this.headersInit.map(([, value]) => value)[Symbol.iterator]();
|
238
235
|
return;
|
239
236
|
}
|
@@ -256,7 +253,7 @@ class PonyfillHeaders {
|
|
256
253
|
}
|
257
254
|
if (!this._map) {
|
258
255
|
if (this.headersInit) {
|
259
|
-
if (
|
256
|
+
if ((0, utils_js_1.isArray)(this.headersInit)) {
|
260
257
|
yield* this.headersInit;
|
261
258
|
return;
|
262
259
|
}
|
package/cjs/Response.js
CHANGED
@@ -4,6 +4,7 @@ exports.PonyfillResponse = void 0;
|
|
4
4
|
const node_http_1 = require("node:http");
|
5
5
|
const Body_js_1 = require("./Body.js");
|
6
6
|
const Headers_js_1 = require("./Headers.js");
|
7
|
+
const utils_js_1 = require("./utils.js");
|
7
8
|
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
8
9
|
class PonyfillResponse extends Body_js_1.PonyfillBody {
|
9
10
|
headers;
|
@@ -66,7 +67,7 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
66
67
|
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
67
68
|
}
|
68
69
|
}
|
69
|
-
else if (
|
70
|
+
else if ((0, utils_js_1.isArray)(init.headers)) {
|
70
71
|
if (!init.headers.some(([key]) => key.toLowerCase() === 'content-type')) {
|
71
72
|
init.headers.push(['content-type', JSON_CONTENT_TYPE]);
|
72
73
|
}
|
package/cjs/utils.js
CHANGED
@@ -10,6 +10,7 @@ exports.shouldRedirect = shouldRedirect;
|
|
10
10
|
exports.wrapIncomingMessageWithPassthrough = wrapIncomingMessageWithPassthrough;
|
11
11
|
exports.endStream = endStream;
|
12
12
|
exports.safeWrite = safeWrite;
|
13
|
+
exports.isArray = isArray;
|
13
14
|
const node_events_1 = require("node:events");
|
14
15
|
const node_stream_1 = require("node:stream");
|
15
16
|
const promises_1 = require("node:stream/promises");
|
@@ -73,3 +74,6 @@ function safeWrite(chunk, stream, signal) {
|
|
73
74
|
});
|
74
75
|
}
|
75
76
|
}
|
77
|
+
function isArray(value) {
|
78
|
+
return value?.length && value?.map && value?.slice && value?.splice;
|
79
|
+
}
|
package/esm/Headers.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { inspect } from 'node:util';
|
2
2
|
import { PonyfillIteratorObject } from './IteratorObject.js';
|
3
|
+
import { isArray } from './utils.js';
|
3
4
|
export function isHeadersLike(headers) {
|
4
5
|
return headers?.get && headers?.forEach;
|
5
6
|
}
|
@@ -26,7 +27,7 @@ export class PonyfillHeaders {
|
|
26
27
|
if (this.headersInit == null) {
|
27
28
|
return null;
|
28
29
|
}
|
29
|
-
if (
|
30
|
+
if (isArray(this.headersInit)) {
|
30
31
|
const found = this.headersInit.filter(([headerKey]) => headerKey.toLowerCase() === normalized);
|
31
32
|
if (found.length === 0) {
|
32
33
|
return null;
|
@@ -64,7 +65,7 @@ export class PonyfillHeaders {
|
|
64
65
|
if (!this._map) {
|
65
66
|
this._setCookies = [];
|
66
67
|
if (this.headersInit != null) {
|
67
|
-
if (
|
68
|
+
if (isArray(this.headersInit)) {
|
68
69
|
this._map = new Map();
|
69
70
|
for (const [key, value] of this.headersInit) {
|
70
71
|
const normalizedKey = key.toLowerCase();
|
@@ -138,12 +139,8 @@ export class PonyfillHeaders {
|
|
138
139
|
this._setCookies = [value];
|
139
140
|
return;
|
140
141
|
}
|
141
|
-
if (this._map) {
|
142
|
-
this.
|
143
|
-
return;
|
144
|
-
}
|
145
|
-
if (this.headersInit != null) {
|
146
|
-
if (Array.isArray(this.headersInit)) {
|
142
|
+
if (!this._map && this.headersInit != null) {
|
143
|
+
if (isArray(this.headersInit)) {
|
147
144
|
const found = this.headersInit.find(([headerKey]) => headerKey.toLowerCase() === key);
|
148
145
|
if (found) {
|
149
146
|
found[1] = value;
|
@@ -178,7 +175,7 @@ export class PonyfillHeaders {
|
|
178
175
|
});
|
179
176
|
if (!this._map) {
|
180
177
|
if (this.headersInit) {
|
181
|
-
if (
|
178
|
+
if (isArray(this.headersInit)) {
|
182
179
|
this.headersInit.forEach(([key, value]) => {
|
183
180
|
callback(value, key, this);
|
184
181
|
});
|
@@ -206,7 +203,7 @@ export class PonyfillHeaders {
|
|
206
203
|
}
|
207
204
|
if (!this._map) {
|
208
205
|
if (this.headersInit) {
|
209
|
-
if (
|
206
|
+
if (isArray(this.headersInit)) {
|
210
207
|
yield* this.headersInit.map(([key]) => key)[Symbol.iterator]();
|
211
208
|
return;
|
212
209
|
}
|
@@ -229,7 +226,7 @@ export class PonyfillHeaders {
|
|
229
226
|
}
|
230
227
|
if (!this._map) {
|
231
228
|
if (this.headersInit) {
|
232
|
-
if (
|
229
|
+
if (isArray(this.headersInit)) {
|
233
230
|
yield* this.headersInit.map(([, value]) => value)[Symbol.iterator]();
|
234
231
|
return;
|
235
232
|
}
|
@@ -252,7 +249,7 @@ export class PonyfillHeaders {
|
|
252
249
|
}
|
253
250
|
if (!this._map) {
|
254
251
|
if (this.headersInit) {
|
255
|
-
if (
|
252
|
+
if (isArray(this.headersInit)) {
|
256
253
|
yield* this.headersInit;
|
257
254
|
return;
|
258
255
|
}
|
package/esm/Response.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { STATUS_CODES } from 'node:http';
|
2
2
|
import { PonyfillBody } from './Body.js';
|
3
3
|
import { isHeadersLike, PonyfillHeaders } from './Headers.js';
|
4
|
+
import { isArray } from './utils.js';
|
4
5
|
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
5
6
|
export class PonyfillResponse extends PonyfillBody {
|
6
7
|
headers;
|
@@ -63,7 +64,7 @@ export class PonyfillResponse extends PonyfillBody {
|
|
63
64
|
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
64
65
|
}
|
65
66
|
}
|
66
|
-
else if (
|
67
|
+
else if (isArray(init.headers)) {
|
67
68
|
if (!init.headers.some(([key]) => key.toLowerCase() === 'content-type')) {
|
68
69
|
init.headers.push(['content-type', JSON_CONTENT_TYPE]);
|
69
70
|
}
|
package/esm/utils.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.20-alpha-
|
3
|
+
"version": "0.7.20-alpha-20250515130141-273de2d136d7ccbd40240112221a1f02b9ac5bb7",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/utils.d.cts
CHANGED
package/typings/utils.d.ts
CHANGED