@whatwg-node/node-fetch 0.7.22-alpha-20250526145249-5592a2aa5cd5a8603f5016376c1e6ef0f84f7aab → 0.7.22-alpha-20250526163200-dc90c3024c7fa99ad5eb4e46eeee8988f7e003df
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 +7 -17
- package/esm/Body.js +8 -18
- package/package.json +1 -1
package/cjs/Body.js
CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PonyfillBody = void 0;
|
4
4
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
5
5
|
const node_buffer_1 = require("node:buffer");
|
6
|
-
const node_http_1 = require("node:http");
|
7
6
|
const node_stream_1 = require("node:stream");
|
8
7
|
const busboy_1 = require("@fastify/busboy");
|
9
8
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
@@ -33,7 +32,7 @@ class PonyfillBody {
|
|
33
32
|
this.bodyInit = bodyInit;
|
34
33
|
this.options = options;
|
35
34
|
this._signal = options.signal || null;
|
36
|
-
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit
|
35
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
37
36
|
this._bodyFactory = bodyFactory;
|
38
37
|
this.contentType = contentType;
|
39
38
|
this.contentLength = contentLength;
|
@@ -133,6 +132,11 @@ class PonyfillBody {
|
|
133
132
|
this._chunks = [];
|
134
133
|
return this._chunks;
|
135
134
|
}
|
135
|
+
if (_body.readable.destroyed) {
|
136
|
+
// If the stream is already destroyed, we can resolve immediately
|
137
|
+
this._chunks = [];
|
138
|
+
return this._chunks;
|
139
|
+
}
|
136
140
|
const chunks = [];
|
137
141
|
const deferred = (0, promise_helpers_1.createDeferredPromise)();
|
138
142
|
_body.readable.on('data', function nextChunk(chunk) {
|
@@ -379,7 +383,7 @@ class PonyfillBody {
|
|
379
383
|
}
|
380
384
|
}
|
381
385
|
exports.PonyfillBody = PonyfillBody;
|
382
|
-
function processBodyInit(bodyInit
|
386
|
+
function processBodyInit(bodyInit) {
|
383
387
|
if (bodyInit == null) {
|
384
388
|
return {
|
385
389
|
bodyFactory: () => null,
|
@@ -462,20 +466,6 @@ function processBodyInit(bodyInit, signal) {
|
|
462
466
|
},
|
463
467
|
};
|
464
468
|
}
|
465
|
-
if (bodyInit instanceof node_http_1.IncomingMessage) {
|
466
|
-
const passThrough = (0, utils_js_1.wrapIncomingMessageWithPassthrough)({
|
467
|
-
incomingMessage: bodyInit,
|
468
|
-
signal,
|
469
|
-
});
|
470
|
-
return {
|
471
|
-
bodyType: BodyInitType.Readable,
|
472
|
-
contentType: null,
|
473
|
-
contentLength: null,
|
474
|
-
bodyFactory() {
|
475
|
-
return new ReadableStream_js_1.PonyfillReadableStream(passThrough);
|
476
|
-
},
|
477
|
-
};
|
478
|
-
}
|
479
469
|
if (bodyInit instanceof node_stream_1.Readable) {
|
480
470
|
return {
|
481
471
|
bodyType: BodyInitType.Readable,
|
package/esm/Body.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
2
2
|
import { Buffer } from 'node:buffer';
|
3
|
-
import { IncomingMessage } from 'node:http';
|
4
3
|
import { addAbortSignal, Readable } from 'node:stream';
|
5
4
|
import { Busboy } from '@fastify/busboy';
|
6
5
|
import { createDeferredPromise } from '@whatwg-node/promise-helpers';
|
@@ -8,7 +7,7 @@ import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } f
|
|
8
7
|
import { PonyfillFile } from './File.js';
|
9
8
|
import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
|
10
9
|
import { PonyfillReadableStream } from './ReadableStream.js';
|
11
|
-
import { fakePromise, isArrayBufferView
|
10
|
+
import { fakePromise, isArrayBufferView } from './utils.js';
|
12
11
|
var BodyInitType;
|
13
12
|
(function (BodyInitType) {
|
14
13
|
BodyInitType["ReadableStream"] = "ReadableStream";
|
@@ -30,7 +29,7 @@ export class PonyfillBody {
|
|
30
29
|
this.bodyInit = bodyInit;
|
31
30
|
this.options = options;
|
32
31
|
this._signal = options.signal || null;
|
33
|
-
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit
|
32
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
34
33
|
this._bodyFactory = bodyFactory;
|
35
34
|
this.contentType = contentType;
|
36
35
|
this.contentLength = contentLength;
|
@@ -130,6 +129,11 @@ export class PonyfillBody {
|
|
130
129
|
this._chunks = [];
|
131
130
|
return this._chunks;
|
132
131
|
}
|
132
|
+
if (_body.readable.destroyed) {
|
133
|
+
// If the stream is already destroyed, we can resolve immediately
|
134
|
+
this._chunks = [];
|
135
|
+
return this._chunks;
|
136
|
+
}
|
133
137
|
const chunks = [];
|
134
138
|
const deferred = createDeferredPromise();
|
135
139
|
_body.readable.on('data', function nextChunk(chunk) {
|
@@ -375,7 +379,7 @@ export class PonyfillBody {
|
|
375
379
|
});
|
376
380
|
}
|
377
381
|
}
|
378
|
-
function processBodyInit(bodyInit
|
382
|
+
function processBodyInit(bodyInit) {
|
379
383
|
if (bodyInit == null) {
|
380
384
|
return {
|
381
385
|
bodyFactory: () => null,
|
@@ -458,20 +462,6 @@ function processBodyInit(bodyInit, signal) {
|
|
458
462
|
},
|
459
463
|
};
|
460
464
|
}
|
461
|
-
if (bodyInit instanceof IncomingMessage) {
|
462
|
-
const passThrough = wrapIncomingMessageWithPassthrough({
|
463
|
-
incomingMessage: bodyInit,
|
464
|
-
signal,
|
465
|
-
});
|
466
|
-
return {
|
467
|
-
bodyType: BodyInitType.Readable,
|
468
|
-
contentType: null,
|
469
|
-
contentLength: null,
|
470
|
-
bodyFactory() {
|
471
|
-
return new PonyfillReadableStream(passThrough);
|
472
|
-
},
|
473
|
-
};
|
474
|
-
}
|
475
465
|
if (bodyInit instanceof Readable) {
|
476
466
|
return {
|
477
467
|
bodyType: BodyInitType.Readable,
|
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-20250526163200-dc90c3024c7fa99ad5eb4e46eeee8988f7e003df",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|