Skip to content

Commit 7f0f6c9

Browse files
authored
fix: extract noop everywhere (#3559)
1 parent 57f1b4e commit 7f0f6c9

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/dispatcher/client.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const connectH2 = require('./client-h2.js')
6060

6161
const kClosedResolve = Symbol('kClosedResolve')
6262

63+
const noop = () => {}
64+
6365
function getPipelining (client) {
6466
return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1
6567
}
@@ -418,7 +420,7 @@ async function connect (client) {
418420
})
419421

420422
if (client.destroyed) {
421-
util.destroy(socket.on('error', () => {}), new ClientDestroyedError())
423+
util.destroy(socket.on('error', noop), new ClientDestroyedError())
422424
return
423425
}
424426

@@ -429,7 +431,7 @@ async function connect (client) {
429431
? await connectH2(client, socket)
430432
: await connectH1(client, socket)
431433
} catch (err) {
432-
socket.destroy().on('error', () => {})
434+
socket.destroy().on('error', noop)
433435
throw err
434436
}
435437

lib/dispatcher/proxy-agent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function defaultFactory (origin, opts) {
2323
return new Pool(origin, opts)
2424
}
2525

26+
const noop = () => {}
27+
2628
class ProxyAgent extends DispatcherBase {
2729
constructor (opts) {
2830
if (!opts || (typeof opts === 'object' && !(opts instanceof URL) && !opts.uri)) {
@@ -78,7 +80,7 @@ class ProxyAgent extends DispatcherBase {
7880
servername: this[kProxyTls]?.servername || proxyHostname
7981
})
8082
if (statusCode !== 200) {
81-
socket.on('error', () => {}).destroy()
83+
socket.on('error', noop).destroy()
8284
callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`))
8385
}
8486
if (opts.protocol !== 'https:') {

lib/web/fetch/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const { webidl } = require('./webidl')
6565
const { STATUS_CODES } = require('node:http')
6666
const GET_OR_HEAD = ['GET', 'HEAD']
6767

68+
const noop = () => {}
69+
6870
const defaultUserAgent = typeof __UNDICI_IS_NODE__ !== 'undefined' || typeof esbuildDetection !== 'undefined'
6971
? 'node'
7072
: 'undici'
@@ -2164,8 +2166,8 @@ async function httpNetworkFetch (
21642166
statusText,
21652167
headersList,
21662168
body: decoders.length
2167-
? pipeline(this.body, ...decoders, () => { })
2168-
: this.body.on('error', () => { })
2169+
? pipeline(this.body, ...decoders, noop)
2170+
: this.body.on('error', noop)
21692171
})
21702172

21712173
return true

0 commit comments

Comments
 (0)