Skip to content

Commit

Permalink
refactor: version cleanup (#2605)
Browse files Browse the repository at this point in the history
* refactor: version cleanup

* remove skip

* remove comment

* remove ` --unhandled-rejections=throw`
  • Loading branch information
tsctx committed Jan 8, 2024
1 parent 887d1cb commit 00f999d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 29 deletions.
10 changes: 2 additions & 8 deletions lib/core/util.js
Expand Up @@ -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) {
Expand Down
7 changes: 0 additions & 7 deletions lib/fetch/index.js
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions test/client-node-max-header-size.js
Expand Up @@ -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'
)
Expand Down
3 changes: 1 addition & 2 deletions test/fetch/client-node-max-header-size.js
Expand Up @@ -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'
)
Expand Down
10 changes: 4 additions & 6 deletions test/fetch/response.js
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
})
})

Expand Down
2 changes: 1 addition & 1 deletion types/dispatcher.d.ts
Expand Up @@ -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<ArrayBuffer>;
blob(): Promise<Blob>;
Expand Down
5 changes: 2 additions & 3 deletions types/readable.d.ts
Expand Up @@ -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
*
Expand Down

0 comments on commit 00f999d

Please sign in to comment.