From e5e36ed492861463c86757b64e036e5526150bd4 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Sat, 7 Sep 2024 00:08:36 +0200 Subject: [PATCH] fix: extract noop everywhere --- lib/dispatcher/client.js | 6 ++++-- lib/dispatcher/proxy-agent.js | 4 +++- lib/web/fetch/index.js | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/dispatcher/client.js b/lib/dispatcher/client.js index 4914dbc1a22..65380f19167 100644 --- a/lib/dispatcher/client.js +++ b/lib/dispatcher/client.js @@ -60,6 +60,8 @@ const connectH2 = require('./client-h2.js') const kClosedResolve = Symbol('kClosedResolve') +const noop = () => {} + function getPipelining (client) { return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1 } @@ -418,7 +420,7 @@ async function connect (client) { }) if (client.destroyed) { - util.destroy(socket.on('error', () => {}), new ClientDestroyedError()) + util.destroy(socket.on('error', noop), new ClientDestroyedError()) return } @@ -429,7 +431,7 @@ async function connect (client) { ? await connectH2(client, socket) : await connectH1(client, socket) } catch (err) { - socket.destroy().on('error', () => {}) + socket.destroy().on('error', noop) throw err } diff --git a/lib/dispatcher/proxy-agent.js b/lib/dispatcher/proxy-agent.js index 8d8db35e338..c5b4d51babb 100644 --- a/lib/dispatcher/proxy-agent.js +++ b/lib/dispatcher/proxy-agent.js @@ -23,6 +23,8 @@ function defaultFactory (origin, opts) { return new Pool(origin, opts) } +const noop = () => {} + class ProxyAgent extends DispatcherBase { constructor (opts) { if (!opts || (typeof opts === 'object' && !(opts instanceof URL) && !opts.uri)) { @@ -78,7 +80,7 @@ class ProxyAgent extends DispatcherBase { servername: this[kProxyTls]?.servername || proxyHostname }) if (statusCode !== 200) { - socket.on('error', () => {}).destroy() + socket.on('error', noop).destroy() callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`)) } if (opts.protocol !== 'https:') { diff --git a/lib/web/fetch/index.js b/lib/web/fetch/index.js index 025248d9742..8e30a90179e 100644 --- a/lib/web/fetch/index.js +++ b/lib/web/fetch/index.js @@ -65,6 +65,8 @@ const { webidl } = require('./webidl') const { STATUS_CODES } = require('node:http') const GET_OR_HEAD = ['GET', 'HEAD'] +const noop = () => {} + const defaultUserAgent = typeof __UNDICI_IS_NODE__ !== 'undefined' || typeof esbuildDetection !== 'undefined' ? 'node' : 'undici' @@ -2164,8 +2166,8 @@ async function httpNetworkFetch ( statusText, headersList, body: decoders.length - ? pipeline(this.body, ...decoders, () => { }) - : this.body.on('error', () => { }) + ? pipeline(this.body, ...decoders, noop) + : this.body.on('error', noop) }) return true