From 81e0a9390629dbb8980e4e23640739f4f9b3fb4a Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Wed, 11 Oct 2023 13:15:23 -0600 Subject: [PATCH 01/11] Revert "include esbuild script in files" This reverts commit 5351f1fdb1f49f86e356056d7beb291af0144390. --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 67046ad68a3..f8a916ad5b6 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,7 @@ "index-fetch.js", "lib", "types", - "docs", - "scripts/esbuild-build.mjs" + "docs" ], "scripts": { "build:node": "node scripts/esbuild-build.mjs", From 655d3d71473a88b3dedb51ba8dc163ca9e7c01e3 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 11 Oct 2023 20:40:12 +0100 Subject: [PATCH 02/11] Revert "Revert "include esbuild script in files"" This reverts commit 81e0a9390629dbb8980e4e23640739f4f9b3fb4a. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f8a916ad5b6..67046ad68a3 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,8 @@ "index-fetch.js", "lib", "types", - "docs" + "docs", + "scripts/esbuild-build.mjs" ], "scripts": { "build:node": "node scripts/esbuild-build.mjs", From 026c1d5ffc38017425fd4e477bf1241f7841afc7 Mon Sep 17 00:00:00 2001 From: Khafra Date: Wed, 11 Oct 2023 17:38:13 -0400 Subject: [PATCH 03/11] use esbuild define/hooks (#2342) * use esbuild define/hooks * remove build script --- package.json | 6 ++---- scripts/esbuild-build.mjs | 24 ------------------------ 2 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 scripts/esbuild-build.mjs diff --git a/package.json b/package.json index 67046ad68a3..6c4b6f4abfd 100644 --- a/package.json +++ b/package.json @@ -67,11 +67,10 @@ "index-fetch.js", "lib", "types", - "docs", - "scripts/esbuild-build.mjs" + "docs" ], "scripts": { - "build:node": "node scripts/esbuild-build.mjs", + "build:node": "npx esbuild@0.19.4 index-fetch.js --bundle --platform=node --outfile=undici-fetch.js --define:esbuildDetection=1", "prebuild:wasm": "node build/wasm.js --prebuild", "build:wasm": "node build/wasm.js --docker", "lint": "standard | snazzy", @@ -110,7 +109,6 @@ "delay": "^5.0.0", "dns-packet": "^5.4.0", "docsify-cli": "^4.4.3", - "esbuild": "^0.19.4", "form-data": "^4.0.0", "formdata-node": "^4.3.1", "https-pem": "^3.0.0", diff --git a/scripts/esbuild-build.mjs b/scripts/esbuild-build.mjs deleted file mode 100644 index ca5886c1a2b..00000000000 --- a/scripts/esbuild-build.mjs +++ /dev/null @@ -1,24 +0,0 @@ -import * as esbuild from 'esbuild' -import fs from 'node:fs' - -const bundle = { - name: 'bundle', - setup (build) { - build.onLoad({ filter: /lib(\/|\\)fetch(\/|\\)index.js/ }, async (args) => { - const text = await fs.promises.readFile(args.path, 'utf8') - - return { - contents: `var esbuildDetection = 1;${text}`, - loader: 'js' - } - }) - } -} - -await esbuild.build({ - entryPoints: ['index-fetch.js'], - bundle: true, - outfile: 'undici-fetch.js', - plugins: [bundle], - platform: 'node' -}) From c740cbb90950c1234ae9eb511d29db1f1ee01ddd Mon Sep 17 00:00:00 2001 From: Khafra Date: Thu, 12 Oct 2023 20:55:19 -0400 Subject: [PATCH 04/11] fix request's arrayBuffer returning uint8 instead of arraybuffer (#2344) --- lib/api/readable.js | 2 +- test/client-request.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/api/readable.js b/lib/api/readable.js index 508fbdef928..d106568cd4b 100644 --- a/lib/api/readable.js +++ b/lib/api/readable.js @@ -268,7 +268,7 @@ function consumeEnd (consume) { pos += buf.byteLength } - resolve(dst) + resolve(dst.buffer) } else if (type === 'blob') { if (!Blob) { Blob = require('buffer').Blob diff --git a/test/client-request.js b/test/client-request.js index 703cedf6803..3e6670523b8 100644 --- a/test/client-request.js +++ b/test/client-request.js @@ -413,7 +413,7 @@ test('request blob', { skip: nodeMajor < 16 }, (t) => { }) test('request arrayBuffer', (t) => { - t.plan(1) + t.plan(2) const obj = { asd: true } const server = createServer((req, res) => { @@ -429,7 +429,10 @@ test('request arrayBuffer', (t) => { path: '/', method: 'GET' }) - t.strictSame(Buffer.from(JSON.stringify(obj)), Buffer.from(await body.arrayBuffer())) + const ab = await body.arrayBuffer() + + t.strictSame(Buffer.from(JSON.stringify(obj)), Buffer.from(ab)) + t.ok(ab instanceof ArrayBuffer) }) }) From e3de712b1d176753950fcfb04ececdd9a4ddfd06 Mon Sep 17 00:00:00 2001 From: Yoann Gendrey Date: Sat, 14 Oct 2023 06:35:41 +0200 Subject: [PATCH 05/11] fix: skip readMore call if parser is null or undefined (#2346) --- lib/client.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 065fb563380..00f4467cc8b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1070,7 +1070,9 @@ function onParserTimeout (parser) { function onSocketReadable () { const { [kParser]: parser } = this - parser.readMore() + if (parser) { + parser.readMore() + } } function onSocketError (err) { From 40ab05029814c9778b80657d530e943d1cdfc6f2 Mon Sep 17 00:00:00 2001 From: Carlos Fuentes Date: Sun, 15 Oct 2023 15:43:39 +0200 Subject: [PATCH 06/11] test: first attempt for flaky fix (#2337) --- test/fetch/http2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fetch/http2.js b/test/fetch/http2.js index b426de3cbe5..32fb33e14eb 100644 --- a/test/fetch/http2.js +++ b/test/fetch/http2.js @@ -193,11 +193,11 @@ test( ':status': 200 }) - stream.end('hello h2!') - for await (const chunk of stream) { requestChunks.push(chunk) } + + stream.end('hello h2!') }) t.plan(8) From 52a79891f95a20fe380d70cfdf8f8f52410ff1a3 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 17 Oct 2023 11:06:03 +0200 Subject: [PATCH 07/11] test: only include WebSocket in WPT Report where it's landed (#2351) --- package.json | 2 +- test/wpt/start-websockets.mjs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c4b6f4abfd..2519a2fb457 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w", "test:typescript": "node scripts/verifyVersion.js 14 || tsd && tsc --skipLibCheck test/imports/undici-import.ts", "test:websocket": "node scripts/verifyVersion.js 18 || tap test/websocket/*.js", - "test:wpt": "node scripts/verifyVersion 18 || (node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node --no-warnings test/wpt/start-websockets.mjs)", + "test:wpt": "node scripts/verifyVersion 18 || (node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node --no-warnings --expose-internals test/wpt/start-websockets.mjs)", "coverage": "nyc --reporter=text --reporter=html npm run test", "coverage:ci": "nyc --reporter=lcov npm run test", "bench": "PORT=3042 concurrently -k -s first npm:bench:server npm:bench:run", diff --git a/test/wpt/start-websockets.mjs b/test/wpt/start-websockets.mjs index 73fd945c4d6..29c9e676d3f 100644 --- a/test/wpt/start-websockets.mjs +++ b/test/wpt/start-websockets.mjs @@ -3,9 +3,18 @@ import { join } from 'path' import { fileURLToPath } from 'url' import { fork } from 'child_process' import { on } from 'events' +import options from 'internal/options' const { WPT_REPORT } = process.env +function isGlobalAvailable () { + if (typeof WebSocket !== 'undefined') { + return true + } + + return typeof options.getOptionValue('--experimental-websocket') === 'boolean' +} + if (process.env.CI) { // TODO(@KhafraDev): figure out *why* these tests are flaky in the CI. // process.exit(0) @@ -22,7 +31,7 @@ child.on('exit', (code) => process.exit(code)) for await (const [message] of on(child, 'message')) { if (message.server) { const runner = new WPTRunner('websockets', message.server, { - appendReport: !!WPT_REPORT, + appendReport: !!WPT_REPORT && isGlobalAvailable(), reportPath: WPT_REPORT }) runner.run() From 49254c3ea1cc74a01132b8c0a9274cbf94c7289e Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 17 Oct 2023 16:59:17 +0200 Subject: [PATCH 08/11] Update DispatchInterceptor.md (#2354) --- docs/api/DispatchInterceptor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/DispatchInterceptor.md b/docs/api/DispatchInterceptor.md index 652b2e86bf9..7dfc260e32a 100644 --- a/docs/api/DispatchInterceptor.md +++ b/docs/api/DispatchInterceptor.md @@ -1,4 +1,4 @@ -#Interface: DispatchInterceptor +# Interface: DispatchInterceptor Extends: `Function` From daf349f6bc35c2e7fe600c323fb7dcfdacc000f6 Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Wed, 18 Oct 2023 23:11:07 +0300 Subject: [PATCH 09/11] fix: Avoid error for stream() being aborted (#2355) Co-authored-by: BobNobrain --- lib/api/api-stream.js | 10 +++++++- test/issue-2349.js | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/issue-2349.js diff --git a/lib/api/api-stream.js b/lib/api/api-stream.js index 3a8e71a5730..c571a6f79a7 100644 --- a/lib/api/api-stream.js +++ b/lib/api/api-stream.js @@ -104,6 +104,10 @@ class StreamHandler extends AsyncResource { { callback, body: res, contentType, statusCode, statusMessage, headers } ) } else { + if (factory === null) { + return + } + res = this.runInAsyncScope(factory, null, { statusCode, headers, @@ -152,7 +156,7 @@ class StreamHandler extends AsyncResource { onData (chunk) { const { res } = this - return res.write(chunk) + return res ? res.write(chunk) : true } onComplete (trailers) { @@ -160,6 +164,10 @@ class StreamHandler extends AsyncResource { removeSignal(this) + if (!res) { + return + } + this.trailers = util.parseHeaders(trailers) res.end() diff --git a/test/issue-2349.js b/test/issue-2349.js new file mode 100644 index 00000000000..a82bb74a261 --- /dev/null +++ b/test/issue-2349.js @@ -0,0 +1,53 @@ +'use strict' + +const { test, skip } = require('tap') +const { nodeMajor } = require('../lib/core/util') +const { Writable } = require('stream') +const { MockAgent, errors, stream } = require('..') + +if (nodeMajor < 16) { + skip('only for node 16') + process.exit(0) +} + +test('stream() does not fail after request has been aborted', async (t) => { + t.plan(1) + + const mockAgent = new MockAgent() + + mockAgent.disableNetConnect() + mockAgent + .get('http://localhost:3333') + .intercept({ + path: '/' + }) + .reply(200, 'ok') + .delay(10) + + const parts = [] + const ac = new AbortController() + + setTimeout(() => ac.abort('nevermind'), 5) + + try { + await stream( + 'http://localhost:3333/', + { + opaque: { parts }, + signal: ac.signal, + dispatcher: mockAgent + }, + ({ opaque: { parts } }) => { + return new Writable({ + write (chunk, _encoding, callback) { + parts.push(chunk) + callback() + } + }) + } + ) + } catch (error) { + console.log(error) + t.equal(error instanceof errors.RequestAbortedError, true) + } +}) From 0681760ef1b24a9ddcb257b1a6a121d1825a67c0 Mon Sep 17 00:00:00 2001 From: Khafra Date: Thu, 19 Oct 2023 01:02:41 -0400 Subject: [PATCH 10/11] fix names with esbuild (#2359) --- package.json | 2 +- test/fetch/bundle.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/fetch/bundle.js diff --git a/package.json b/package.json index 2519a2fb457..f92164f9aaf 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "docs" ], "scripts": { - "build:node": "npx esbuild@0.19.4 index-fetch.js --bundle --platform=node --outfile=undici-fetch.js --define:esbuildDetection=1", + "build:node": "npx esbuild@0.19.4 index-fetch.js --bundle --platform=node --outfile=undici-fetch.js --define:esbuildDetection=1 --keep-names", "prebuild:wasm": "node build/wasm.js --prebuild", "build:wasm": "node build/wasm.js --docker", "lint": "standard | snazzy", diff --git a/test/fetch/bundle.js b/test/fetch/bundle.js new file mode 100644 index 00000000000..3b35cfc04aa --- /dev/null +++ b/test/fetch/bundle.js @@ -0,0 +1,20 @@ +'use strict' + +const { test } = require('tap') +const { Response, Request, FormData, Headers } = require('../../undici-fetch') + +test('bundle sets constructor.name and .name properly', (t) => { + t.equal(new Response().constructor.name, 'Response') + t.equal(Response.name, 'Response') + + t.equal(new Request('http://a').constructor.name, 'Request') + t.equal(Request.name, 'Request') + + t.equal(new Headers().constructor.name, 'Headers') + t.equal(Headers.name, 'Headers') + + t.equal(new FormData().constructor.name, 'FormData') + t.equal(FormData.name, 'FormData') + + t.end() +}) From dea70e27e4d14952eb7b96da021eb44d24d1159e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 19 Oct 2023 10:45:52 +0200 Subject: [PATCH 11/11] Bumped v5.26.4 Signed-off-by: Matteo Collina --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f92164f9aaf..31e157de002 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "undici", - "version": "5.26.3", + "version": "5.26.4", "description": "An HTTP/1.1 client, written from scratch for Node.js", "homepage": "https://undici.nodejs.org", "bugs": {