Merge pull request #20552 from overleaf/ac-update-node-fetch-2

Reapply "Upgrade node-fetch to 2.7.0", Fix fetch-utils tests

GitOrigin-RevId: b42a2d2c50ce73f474e39755845e4df065f30b48
This commit is contained in:
Antoine Clausse
2024-10-01 08:05:18 +00:00
committed by Copybot
parent 9997c4874f
commit 6c2cf20125
11 changed files with 107 additions and 409 deletions
@@ -1,5 +1,5 @@
diff --git a/node_modules/node-fetch/lib/index.js b/node_modules/node-fetch/lib/index.js
index e5b04f1..8c80924 100644
index 567ff5d..8eb45f7 100644
--- a/node_modules/node-fetch/lib/index.js
+++ b/node_modules/node-fetch/lib/index.js
@@ -545,8 +545,8 @@ function clone(instance) {
@@ -30,47 +30,47 @@ index e5b04f1..8c80924 100644
}
}
@@ -1594,7 +1594,7 @@ function fetch(url, opts) {
@@ -1638,7 +1638,7 @@ function fetch(url, opts) {
res.once('end', function () {
if (signal) signal.removeEventListener('abort', abortAndFinalize);
});
- let body = res.pipe(new PassThrough$1());
+ let body = new PassThrough$1(); setTimeout(() => Stream.pipeline(res, body, (err) => { if (err) req.abort() }), 0); // Note: let the call-site attach event handler to "body" before we start streaming.
+ let body = Stream.pipeline(res, new PassThrough(), error => { if (error) reject(error); });
const response_options = {
url: request.url,
@@ -1635,7 +1635,7 @@ function fetch(url, opts) {
@@ -1679,7 +1679,7 @@ function fetch(url, opts) {
// for gzip
if (codings == 'gzip' || codings == 'x-gzip') {
- body = body.pipe(zlib.createGunzip(zlibOptions));
+ const bodyGzip = zlib.createGunzip(zlibOptions); Stream.pipeline(body, bodyGzip, () => {}); body = bodyGzip;
+ body = Stream.pipeline(body, zlib.createGunzip(zlibOptions), error => { if (error) reject(error); });
response = new Response(body, response_options);
resolve(response);
return;
@@ -1645,13 +1645,13 @@ function fetch(url, opts) {
@@ -1689,13 +1689,13 @@ function fetch(url, opts) {
if (codings == 'deflate' || codings == 'x-deflate') {
// handle the infamous raw deflate response from old servers
// a hack for old IIS and Apache servers
- const raw = res.pipe(new PassThrough$1());
+ const raw = new PassThrough$1(); setTimeout(() => Stream.pipeline(res, raw, () => {}), 0); // Note: delay piping into "raw" until we start piping into "body".
+ const raw = Stream.pipeline(res, new PassThrough(), error => { if (error) reject(error); });
raw.once('data', function (chunk) {
// see http://stackoverflow.com/questions/37519828
if ((chunk[0] & 0x0F) === 0x08) {
- body = body.pipe(zlib.createInflate());
+ const bodyDeflate = zlib.createInflate(); Stream.pipeline(body, bodyDeflate, () => {}); body = bodyDeflate;
+ body = Stream.pipeline(body, zlib.createInflate(), error => { if (error) reject(error); });
} else {
- body = body.pipe(zlib.createInflateRaw());
+ const bodyDeflate = zlib.createInflateRaw(); Stream.pipeline(body, bodyDeflate, () => {}); body = bodyDeflate;
+ body = Stream.pipeline(body, zlib.createInflateRaw(), error => { if (error) reject(error); });
}
response = new Response(body, response_options);
resolve(response);
@@ -1661,7 +1661,7 @@ function fetch(url, opts) {
@@ -1712,7 +1712,7 @@ function fetch(url, opts) {
// for br
if (codings == 'br' && typeof zlib.createBrotliDecompress === 'function') {
- body = body.pipe(zlib.createBrotliDecompress());
+ const bodyBrotli = zlib.createBrotliDecompress(); Stream.pipeline(body, bodyBrotli, () => {}); body = bodyBrotli;
+ body = Stream.pipeline(body, zlib.createBrotliDecompress(), error => { if (error) reject(error); });
response = new Response(body, response_options);
resolve(response);
return;