@whatwg-node/node-fetch 0.4.4 → 0.4.5-alpha-20230613171038-bc4cd83
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 +5 -3
- package/cjs/Response.js +7 -18
- package/esm/Body.js +5 -3
- package/esm/Response.js +7 -18
- package/package.json +1 -1
package/cjs/Body.js
CHANGED
@@ -232,7 +232,7 @@ function processBodyInit(bodyInit) {
|
|
232
232
|
};
|
233
233
|
}
|
234
234
|
if (bodyInit instanceof Buffer) {
|
235
|
-
const contentLength = bodyInit.
|
235
|
+
const contentLength = bodyInit.byteLength;
|
236
236
|
return {
|
237
237
|
bodyType: BodyInitType.Buffer,
|
238
238
|
contentLength,
|
@@ -245,12 +245,14 @@ function processBodyInit(bodyInit) {
|
|
245
245
|
};
|
246
246
|
}
|
247
247
|
if (typeof bodyInit === 'string') {
|
248
|
+
const buffer = Buffer.from(bodyInit);
|
249
|
+
const contentLength = buffer.byteLength;
|
248
250
|
return {
|
249
251
|
bodyType: BodyInitType.String,
|
250
252
|
contentType: 'text/plain;charset=UTF-8',
|
251
|
-
contentLength
|
253
|
+
contentLength,
|
252
254
|
bodyFactory() {
|
253
|
-
const readable = stream_1.Readable.from(
|
255
|
+
const readable = stream_1.Readable.from(buffer);
|
254
256
|
return new ReadableStream_js_1.PonyfillReadableStream(readable);
|
255
257
|
},
|
256
258
|
};
|
package/cjs/Response.js
CHANGED
@@ -60,25 +60,14 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
60
60
|
});
|
61
61
|
}
|
62
62
|
static json(data, init = {}) {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if (!init.headers.has('content-length')) {
|
70
|
-
bodyInit = Buffer.from(bodyInit);
|
71
|
-
init.headers.set('content-length', bodyInit.byteLength.toString());
|
72
|
-
}
|
73
|
-
}
|
74
|
-
else {
|
75
|
-
bodyInit = Buffer.from(bodyInit);
|
76
|
-
init.headers = [
|
77
|
-
['content-type', JSON_CONTENT_TYPE],
|
78
|
-
['content-length', bodyInit.byteLength.toString()],
|
79
|
-
];
|
63
|
+
init.headers =
|
64
|
+
init?.headers && (0, Headers_js_1.isHeadersLike)(init.headers)
|
65
|
+
? init.headers
|
66
|
+
: new Headers_js_1.PonyfillHeaders(init?.headers);
|
67
|
+
if (!init.headers.has('content-type')) {
|
68
|
+
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
80
69
|
}
|
81
|
-
return new PonyfillResponse(
|
70
|
+
return new PonyfillResponse(JSON.stringify(data), init);
|
82
71
|
}
|
83
72
|
}
|
84
73
|
exports.PonyfillResponse = PonyfillResponse;
|
package/esm/Body.js
CHANGED
@@ -227,7 +227,7 @@ function processBodyInit(bodyInit) {
|
|
227
227
|
};
|
228
228
|
}
|
229
229
|
if (bodyInit instanceof Buffer) {
|
230
|
-
const contentLength = bodyInit.
|
230
|
+
const contentLength = bodyInit.byteLength;
|
231
231
|
return {
|
232
232
|
bodyType: BodyInitType.Buffer,
|
233
233
|
contentLength,
|
@@ -240,12 +240,14 @@ function processBodyInit(bodyInit) {
|
|
240
240
|
};
|
241
241
|
}
|
242
242
|
if (typeof bodyInit === 'string') {
|
243
|
+
const buffer = Buffer.from(bodyInit);
|
244
|
+
const contentLength = buffer.byteLength;
|
243
245
|
return {
|
244
246
|
bodyType: BodyInitType.String,
|
245
247
|
contentType: 'text/plain;charset=UTF-8',
|
246
|
-
contentLength
|
248
|
+
contentLength,
|
247
249
|
bodyFactory() {
|
248
|
-
const readable = Readable.from(
|
250
|
+
const readable = Readable.from(buffer);
|
249
251
|
return new PonyfillReadableStream(readable);
|
250
252
|
},
|
251
253
|
};
|
package/esm/Response.js
CHANGED
@@ -57,24 +57,13 @@ export class PonyfillResponse extends PonyfillBody {
|
|
57
57
|
});
|
58
58
|
}
|
59
59
|
static json(data, init = {}) {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if (!init.headers.has('content-length')) {
|
67
|
-
bodyInit = Buffer.from(bodyInit);
|
68
|
-
init.headers.set('content-length', bodyInit.byteLength.toString());
|
69
|
-
}
|
70
|
-
}
|
71
|
-
else {
|
72
|
-
bodyInit = Buffer.from(bodyInit);
|
73
|
-
init.headers = [
|
74
|
-
['content-type', JSON_CONTENT_TYPE],
|
75
|
-
['content-length', bodyInit.byteLength.toString()],
|
76
|
-
];
|
60
|
+
init.headers =
|
61
|
+
init?.headers && isHeadersLike(init.headers)
|
62
|
+
? init.headers
|
63
|
+
: new PonyfillHeaders(init?.headers);
|
64
|
+
if (!init.headers.has('content-type')) {
|
65
|
+
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
77
66
|
}
|
78
|
-
return new PonyfillResponse(
|
67
|
+
return new PonyfillResponse(JSON.stringify(data), init);
|
79
68
|
}
|
80
69
|
}
|