@whatwg-node/node-fetch 0.7.22-alpha-20250527001401-318441d4ecce8b4db24c1d2d9a90cfb84928b021 → 0.7.22-alpha-20250527020114-bf7a9c1c4bf32e1ca6edd3faf2d7a81370ded65c
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/Body.js +9 -10
- package/cjs/Response.js +0 -52
- package/esm/Body.js +9 -10
- package/esm/Response.js +0 -52
- package/package.json +1 -1
package/cjs/Body.js
CHANGED
@@ -225,10 +225,10 @@ class PonyfillBody {
|
|
225
225
|
});
|
226
226
|
bb.on('field', (name, value, fieldnameTruncated, valueTruncated) => {
|
227
227
|
if (fieldnameTruncated) {
|
228
|
-
|
228
|
+
bb.destroy(new Error(`Field name size exceeded: ${formDataLimits?.fieldNameSize} bytes`));
|
229
229
|
}
|
230
230
|
if (valueTruncated) {
|
231
|
-
|
231
|
+
bb.destroy(new Error(`Field value size exceeded: ${formDataLimits?.fieldSize} bytes`));
|
232
232
|
}
|
233
233
|
this._formData.set(name, value);
|
234
234
|
});
|
@@ -238,24 +238,24 @@ class PonyfillBody {
|
|
238
238
|
chunks.push(chunk);
|
239
239
|
});
|
240
240
|
fileStream.on('limit', () => {
|
241
|
-
|
241
|
+
bb.destroy(new Error(`File size limit exceeded: ${formDataLimits?.fileSize} bytes`));
|
242
242
|
});
|
243
243
|
fileStream.on('close', () => {
|
244
244
|
if (fileStream.truncated) {
|
245
|
-
|
245
|
+
bb.destroy(new Error(`File size limit exceeded: ${formDataLimits?.fileSize} bytes`));
|
246
246
|
}
|
247
247
|
const file = new File_js_1.PonyfillFile(chunks, filename, { type: mimeType });
|
248
248
|
this._formData.set(name, file);
|
249
249
|
});
|
250
250
|
});
|
251
251
|
bb.on('fieldsLimit', () => {
|
252
|
-
|
252
|
+
bb.destroy(new Error(`Fields limit exceeded: ${formDataLimits?.fields}`));
|
253
253
|
});
|
254
254
|
bb.on('filesLimit', () => {
|
255
|
-
|
255
|
+
bb.destroy(new Error(`Files limit exceeded: ${formDataLimits?.files}`));
|
256
256
|
});
|
257
257
|
bb.on('partsLimit', () => {
|
258
|
-
|
258
|
+
bb.destroy(new Error(`Parts limit exceeded: ${formDataLimits?.parts}`));
|
259
259
|
});
|
260
260
|
return (0, promises_1.pipeline)(stream, bb, {
|
261
261
|
signal: this._signal || undefined,
|
@@ -357,11 +357,10 @@ function processBodyInit(bodyInit) {
|
|
357
357
|
};
|
358
358
|
}
|
359
359
|
if (typeof bodyInit === 'string') {
|
360
|
-
const contentLength = node_buffer_1.Buffer.byteLength(bodyInit);
|
361
360
|
return {
|
362
361
|
bodyType: BodyInitType.String,
|
363
|
-
contentType:
|
364
|
-
contentLength,
|
362
|
+
contentType: null,
|
363
|
+
contentLength: null,
|
365
364
|
bodyFactory() {
|
366
365
|
const readable = node_stream_1.Readable.from(node_buffer_1.Buffer.from(bodyInit, 'utf-8'));
|
367
366
|
return new ReadableStream_js_1.PonyfillReadableStream(readable);
|
package/cjs/Response.js
CHANGED
@@ -4,7 +4,6 @@ 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 JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
8
7
|
class PonyfillResponse extends Body_js_1.PonyfillBody {
|
9
8
|
headers;
|
10
9
|
constructor(body, init) {
|
@@ -50,57 +49,6 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
50
49
|
}
|
51
50
|
static json(data, init) {
|
52
51
|
const bodyInit = JSON.stringify(data);
|
53
|
-
if (!init) {
|
54
|
-
init = {
|
55
|
-
headers: {
|
56
|
-
'content-type': JSON_CONTENT_TYPE,
|
57
|
-
'content-length': Buffer.byteLength(bodyInit).toString(),
|
58
|
-
},
|
59
|
-
};
|
60
|
-
}
|
61
|
-
else if (!init.headers) {
|
62
|
-
init.headers = {
|
63
|
-
'content-type': JSON_CONTENT_TYPE,
|
64
|
-
'content-length': Buffer.byteLength(bodyInit).toString(),
|
65
|
-
};
|
66
|
-
}
|
67
|
-
else if ((0, Headers_js_1.isHeadersLike)(init.headers)) {
|
68
|
-
if (!init.headers.has('content-type')) {
|
69
|
-
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
70
|
-
}
|
71
|
-
if (!init.headers.has('content-length')) {
|
72
|
-
init.headers.set('content-length', Buffer.byteLength(bodyInit).toString());
|
73
|
-
}
|
74
|
-
}
|
75
|
-
else if (Array.isArray(init.headers)) {
|
76
|
-
let contentTypeExists = false;
|
77
|
-
let contentLengthExists = false;
|
78
|
-
for (const [key] of init.headers) {
|
79
|
-
if (contentLengthExists && contentTypeExists) {
|
80
|
-
break;
|
81
|
-
}
|
82
|
-
if (!contentTypeExists && key.toLowerCase() === 'content-type') {
|
83
|
-
contentTypeExists = true;
|
84
|
-
}
|
85
|
-
else if (!contentLengthExists && key.toLowerCase() === 'content-length') {
|
86
|
-
contentLengthExists = true;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
if (!contentTypeExists) {
|
90
|
-
init.headers.push(['content-type', JSON_CONTENT_TYPE]);
|
91
|
-
}
|
92
|
-
if (!contentLengthExists) {
|
93
|
-
init.headers.push(['content-length', Buffer.byteLength(bodyInit).toString()]);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
else if (typeof init.headers === 'object') {
|
97
|
-
if (init.headers?.['content-type'] == null) {
|
98
|
-
init.headers['content-type'] = JSON_CONTENT_TYPE;
|
99
|
-
}
|
100
|
-
if (init.headers?.['content-length'] == null) {
|
101
|
-
init.headers['content-length'] = Buffer.byteLength(bodyInit).toString();
|
102
|
-
}
|
103
|
-
}
|
104
52
|
return new PonyfillResponse(bodyInit, init);
|
105
53
|
}
|
106
54
|
[Symbol.toStringTag] = 'Response';
|
package/esm/Body.js
CHANGED
@@ -222,10 +222,10 @@ export class PonyfillBody {
|
|
222
222
|
});
|
223
223
|
bb.on('field', (name, value, fieldnameTruncated, valueTruncated) => {
|
224
224
|
if (fieldnameTruncated) {
|
225
|
-
|
225
|
+
bb.destroy(new Error(`Field name size exceeded: ${formDataLimits?.fieldNameSize} bytes`));
|
226
226
|
}
|
227
227
|
if (valueTruncated) {
|
228
|
-
|
228
|
+
bb.destroy(new Error(`Field value size exceeded: ${formDataLimits?.fieldSize} bytes`));
|
229
229
|
}
|
230
230
|
this._formData.set(name, value);
|
231
231
|
});
|
@@ -235,24 +235,24 @@ export class PonyfillBody {
|
|
235
235
|
chunks.push(chunk);
|
236
236
|
});
|
237
237
|
fileStream.on('limit', () => {
|
238
|
-
|
238
|
+
bb.destroy(new Error(`File size limit exceeded: ${formDataLimits?.fileSize} bytes`));
|
239
239
|
});
|
240
240
|
fileStream.on('close', () => {
|
241
241
|
if (fileStream.truncated) {
|
242
|
-
|
242
|
+
bb.destroy(new Error(`File size limit exceeded: ${formDataLimits?.fileSize} bytes`));
|
243
243
|
}
|
244
244
|
const file = new PonyfillFile(chunks, filename, { type: mimeType });
|
245
245
|
this._formData.set(name, file);
|
246
246
|
});
|
247
247
|
});
|
248
248
|
bb.on('fieldsLimit', () => {
|
249
|
-
|
249
|
+
bb.destroy(new Error(`Fields limit exceeded: ${formDataLimits?.fields}`));
|
250
250
|
});
|
251
251
|
bb.on('filesLimit', () => {
|
252
|
-
|
252
|
+
bb.destroy(new Error(`Files limit exceeded: ${formDataLimits?.files}`));
|
253
253
|
});
|
254
254
|
bb.on('partsLimit', () => {
|
255
|
-
|
255
|
+
bb.destroy(new Error(`Parts limit exceeded: ${formDataLimits?.parts}`));
|
256
256
|
});
|
257
257
|
return pipeline(stream, bb, {
|
258
258
|
signal: this._signal || undefined,
|
@@ -353,11 +353,10 @@ function processBodyInit(bodyInit) {
|
|
353
353
|
};
|
354
354
|
}
|
355
355
|
if (typeof bodyInit === 'string') {
|
356
|
-
const contentLength = Buffer.byteLength(bodyInit);
|
357
356
|
return {
|
358
357
|
bodyType: BodyInitType.String,
|
359
|
-
contentType:
|
360
|
-
contentLength,
|
358
|
+
contentType: null,
|
359
|
+
contentLength: null,
|
361
360
|
bodyFactory() {
|
362
361
|
const readable = Readable.from(Buffer.from(bodyInit, 'utf-8'));
|
363
362
|
return new PonyfillReadableStream(readable);
|
package/esm/Response.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { STATUS_CODES } from 'node:http';
|
2
2
|
import { PonyfillBody } from './Body.js';
|
3
3
|
import { isHeadersLike, PonyfillHeaders } from './Headers.js';
|
4
|
-
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
5
4
|
export class PonyfillResponse extends PonyfillBody {
|
6
5
|
headers;
|
7
6
|
constructor(body, init) {
|
@@ -47,57 +46,6 @@ export class PonyfillResponse extends PonyfillBody {
|
|
47
46
|
}
|
48
47
|
static json(data, init) {
|
49
48
|
const bodyInit = JSON.stringify(data);
|
50
|
-
if (!init) {
|
51
|
-
init = {
|
52
|
-
headers: {
|
53
|
-
'content-type': JSON_CONTENT_TYPE,
|
54
|
-
'content-length': Buffer.byteLength(bodyInit).toString(),
|
55
|
-
},
|
56
|
-
};
|
57
|
-
}
|
58
|
-
else if (!init.headers) {
|
59
|
-
init.headers = {
|
60
|
-
'content-type': JSON_CONTENT_TYPE,
|
61
|
-
'content-length': Buffer.byteLength(bodyInit).toString(),
|
62
|
-
};
|
63
|
-
}
|
64
|
-
else if (isHeadersLike(init.headers)) {
|
65
|
-
if (!init.headers.has('content-type')) {
|
66
|
-
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
67
|
-
}
|
68
|
-
if (!init.headers.has('content-length')) {
|
69
|
-
init.headers.set('content-length', Buffer.byteLength(bodyInit).toString());
|
70
|
-
}
|
71
|
-
}
|
72
|
-
else if (Array.isArray(init.headers)) {
|
73
|
-
let contentTypeExists = false;
|
74
|
-
let contentLengthExists = false;
|
75
|
-
for (const [key] of init.headers) {
|
76
|
-
if (contentLengthExists && contentTypeExists) {
|
77
|
-
break;
|
78
|
-
}
|
79
|
-
if (!contentTypeExists && key.toLowerCase() === 'content-type') {
|
80
|
-
contentTypeExists = true;
|
81
|
-
}
|
82
|
-
else if (!contentLengthExists && key.toLowerCase() === 'content-length') {
|
83
|
-
contentLengthExists = true;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
if (!contentTypeExists) {
|
87
|
-
init.headers.push(['content-type', JSON_CONTENT_TYPE]);
|
88
|
-
}
|
89
|
-
if (!contentLengthExists) {
|
90
|
-
init.headers.push(['content-length', Buffer.byteLength(bodyInit).toString()]);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
else if (typeof init.headers === 'object') {
|
94
|
-
if (init.headers?.['content-type'] == null) {
|
95
|
-
init.headers['content-type'] = JSON_CONTENT_TYPE;
|
96
|
-
}
|
97
|
-
if (init.headers?.['content-length'] == null) {
|
98
|
-
init.headers['content-length'] = Buffer.byteLength(bodyInit).toString();
|
99
|
-
}
|
100
|
-
}
|
101
49
|
return new PonyfillResponse(bodyInit, init);
|
102
50
|
}
|
103
51
|
[Symbol.toStringTag] = 'Response';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.22-alpha-
|
3
|
+
"version": "0.7.22-alpha-20250527020114-bf7a9c1c4bf32e1ca6edd3faf2d7a81370ded65c",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|