From fa77f9549e8f9b25819860e9051a889a34692b49 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:27:48 +0900 Subject: [PATCH 1/4] refactor: version cleanup --- lib/core/util.js | 10 ++-------- lib/fetch/index.js | 7 ------- test/fetch/response.js | 6 ++---- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 7cd411d9f3e..94a8a04c89e 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -349,14 +349,8 @@ function validateHandler (handler, method, upgrade) { // A body is disturbed if it has been read from and it cannot // be re-used without losing state or data. function isDisturbed (body) { - return !!(body && ( - stream.isDisturbed - ? stream.isDisturbed(body) || body[kBodyUsed] // TODO (fix): Why is body[kBodyUsed] needed? - : body[kBodyUsed] || - body.readableDidRead || - (body._readableState && body._readableState.dataEmitted) || - isReadableAborted(body) - )) + // TODO (fix): Why is body[kBodyUsed] needed? + return !!(body && (stream.isDisturbed(body) || body[kBodyUsed])) } function isErrored (body) { diff --git a/lib/fetch/index.js b/lib/fetch/index.js index f16ce4b4536..75f25371410 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -327,13 +327,6 @@ function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, // https://fetch.spec.whatwg.org/#abort-fetch function abortFetch (p, request, responseObject, error) { - // Note: AbortSignal.reason was added in node v17.2.0 - // which would give us an undefined error to reject with. - // Remove this once node v16 is no longer supported. - if (!error) { - error = new DOMException('The operation was aborted.', 'AbortError') - } - // 1. Reject promise with error. p.reject(error) diff --git a/test/fetch/response.js b/test/fetch/response.js index 94b1e8a8199..731ef5cfdfe 100644 --- a/test/fetch/response.js +++ b/test/fetch/response.js @@ -210,14 +210,12 @@ test('constructing a Response with a ReadableStream body', { skip: process.versi const response1 = new Response(readable) const response2 = response1.clone() const response3 = response1.clone() - // const response4 = response1.clone() + const response4 = response1.clone() await assert.rejects(response1.arrayBuffer(), TypeError) await assert.rejects(response2.text(), TypeError) await assert.rejects(response3.json(), TypeError) - // TODO: on Node v16.8.0, this throws a TypeError - // because the body is detected as disturbed. - // await t.rejects(response4.blob(), TypeError) + await assert.rejects(response4.blob(), TypeError) }) }) From 9500266064f97d60eedce6d748c3bac753b05ee8 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:30:42 +0900 Subject: [PATCH 2/4] remove skip --- test/fetch/response.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fetch/response.js b/test/fetch/response.js index 731ef5cfdfe..c22a649ff28 100644 --- a/test/fetch/response.js +++ b/test/fetch/response.js @@ -165,7 +165,7 @@ test('Modifying headers using Headers.prototype.set', () => { }) // https://github.com/nodejs/node/issues/43838 -test('constructing a Response with a ReadableStream body', { skip: process.version.startsWith('v16.') }, async (t) => { +test('constructing a Response with a ReadableStream body', async (t) => { const text = '{"foo":"bar"}' const uint8 = new TextEncoder().encode(text) @@ -199,7 +199,7 @@ test('constructing a Response with a ReadableStream body', { skip: process.versi await assert.rejects(response.text(), TypeError) }) - await t.test('Readable with ArrayBuffer chunk still throws', { skip: process.version.startsWith('v16.') }, async () => { + await t.test('Readable with ArrayBuffer chunk still throws', async () => { const readable = new ReadableStream({ start (controller) { controller.enqueue(uint8.buffer) From 9d1b4123df3abe62a324f3310664350d3229cbf9 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:36:36 +0900 Subject: [PATCH 3/4] remove comment --- types/dispatcher.d.ts | 2 +- types/readable.d.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 5988c8a9c7d..33258aafe49 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -229,7 +229,7 @@ declare namespace Dispatcher { * @link https://fetch.spec.whatwg.org/#body-mixin */ interface BodyMixin { - readonly body?: never; // throws on node v16.6.0 + readonly body?: never; readonly bodyUsed: boolean; arrayBuffer(): Promise; blob(): Promise; diff --git a/types/readable.d.ts b/types/readable.d.ts index 4549a8c87e8..a5fce8a20d3 100644 --- a/types/readable.d.ts +++ b/types/readable.d.ts @@ -44,9 +44,8 @@ declare class BodyReadable extends Readable { */ readonly bodyUsed: boolean - /** Throws on node 16.6.0 - * - * If body is null, it should return null as the body + /** + * If body is null, it should return null as the body * * If body is not null, should return the body as a ReadableStream * From a0bcdf232edfd6a618681b6c6145a7632669191c Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:43:45 +0900 Subject: [PATCH 4/4] remove ` --unhandled-rejections=throw` --- test/client-node-max-header-size.js | 3 +-- test/fetch/client-node-max-header-size.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/client-node-max-header-size.js b/test/client-node-max-header-size.js index b5374901644..b4bd6280249 100644 --- a/test/client-node-max-header-size.js +++ b/test/client-node-max-header-size.js @@ -7,8 +7,7 @@ const command = 'node -e "require(\'.\').request(\'https://httpbin.org/get\')"' test("respect Node.js' --max-http-header-size", async (t) => { t.throws( - // TODO: Drop the `--unhandled-rejections=throw` once we drop Node.js 14 - () => execSync(`${command} --max-http-header-size=1 --unhandled-rejections=throw`), + () => execSync(`${command} --max-http-header-size=1`), /UND_ERR_HEADERS_OVERFLOW/, 'max-http-header-size=1 should throw' ) diff --git a/test/fetch/client-node-max-header-size.js b/test/fetch/client-node-max-header-size.js index 260e11ec378..d044731cf95 100644 --- a/test/fetch/client-node-max-header-size.js +++ b/test/fetch/client-node-max-header-size.js @@ -8,8 +8,7 @@ const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'https://httpbin test("respect Node.js' --max-http-header-size", async () => { assert.throws( - // TODO: Drop the `--unhandled-rejections=throw` once we drop Node.js 14 - () => execSync(`${command} --max-http-header-size=1 --unhandled-rejections=throw`), + () => execSync(`${command} --max-http-header-size=1`), /UND_ERR_HEADERS_OVERFLOW/, 'max-http-header-size=1 should throw' )