mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[Node 24.17.0][Platform packages] Fix node-fetch keep-alive false positive and bump clsi yauzl for Node 24.17 GitOrigin-RevId: 9e0382533d45e1e3b3ed88d4ccfc577591666e10
98 lines
3.9 KiB
Diff
98 lines
3.9 KiB
Diff
diff --git a/lib/index.js b/lib/index.js
|
|
index 567ff5d..a7a38dd 100644
|
|
--- a/lib/index.js
|
|
+++ b/lib/index.js
|
|
@@ -545,8 +545,8 @@ function clone(instance) {
|
|
// tee instance body
|
|
p1 = new PassThrough();
|
|
p2 = new PassThrough();
|
|
- body.pipe(p1);
|
|
- body.pipe(p2);
|
|
+ Stream.pipeline(body, p1, () => {});
|
|
+ Stream.pipeline(body, p2, () => {});
|
|
// set instance body to teed body and return the other teed body
|
|
instance[INTERNALS].body = p1;
|
|
body = p2;
|
|
@@ -648,14 +648,14 @@ function writeToStream(dest, instance) {
|
|
// body is null
|
|
dest.end();
|
|
} else if (isBlob(body)) {
|
|
- body.stream().pipe(dest);
|
|
+ Stream.pipeline(body.stream(), dest, () => {});
|
|
} else if (Buffer.isBuffer(body)) {
|
|
// body is buffer
|
|
dest.write(body);
|
|
dest.end();
|
|
} else {
|
|
// body is stream
|
|
- body.pipe(dest);
|
|
+ Stream.pipeline(body, dest, () => {});
|
|
}
|
|
}
|
|
|
|
@@ -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 = Stream.pipeline(res, new PassThrough(), error => { if (error) reject(error); });
|
|
|
|
const response_options = {
|
|
url: request.url,
|
|
@@ -1679,7 +1679,7 @@ function fetch(url, opts) {
|
|
|
|
// for gzip
|
|
if (codings == 'gzip' || codings == 'x-gzip') {
|
|
- body = body.pipe(zlib.createGunzip(zlibOptions));
|
|
+ body = Stream.pipeline(body, zlib.createGunzip(zlibOptions), error => { if (error) reject(error); });
|
|
response = new Response(body, response_options);
|
|
resolve(response);
|
|
return;
|
|
@@ -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 = 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());
|
|
+ body = Stream.pipeline(body, zlib.createInflate(), error => { if (error) reject(error); });
|
|
} else {
|
|
- body = body.pipe(zlib.createInflateRaw());
|
|
+ body = Stream.pipeline(body, zlib.createInflateRaw(), error => { if (error) reject(error); });
|
|
}
|
|
response = new Response(body, response_options);
|
|
resolve(response);
|
|
@@ -1712,7 +1712,7 @@ function fetch(url, opts) {
|
|
|
|
// for br
|
|
if (codings == 'br' && typeof zlib.createBrotliDecompress === 'function') {
|
|
- body = body.pipe(zlib.createBrotliDecompress());
|
|
+ body = Stream.pipeline(body, zlib.createBrotliDecompress(), error => { if (error) reject(error); });
|
|
response = new Response(body, response_options);
|
|
resolve(response);
|
|
return;
|
|
@@ -1738,13 +1738,13 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
|
|
if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) {
|
|
response.once('close', function (hadError) {
|
|
- // tests for socket presence, as in some situations the
|
|
- // the 'socket' event is not triggered for the request
|
|
- // (happens in deno), avoids `TypeError`
|
|
- // if a data listener is still present we didn't end cleanly
|
|
- const hasDataListener = socket && socket.listenerCount('data') > 0;
|
|
-
|
|
- if (hasDataListener && !hadError) {
|
|
+ // A kept-alive socket (Node >= 24.16) still has its 'data'
|
|
+ // listener attached when the response 'close' event fires, so
|
|
+ // the old socket.listenerCount('data') check reported a false
|
|
+ // "Premature close". response.complete is true only once the
|
|
+ // terminating zero-length chunk has been received, so it tells
|
|
+ // a clean end apart from a genuine truncation.
|
|
+ if (!response.complete && !hadError) {
|
|
const err = new Error('Premature close');
|
|
err.code = 'ERR_STREAM_PREMATURE_CLOSE';
|
|
errorCallback(err);
|