Skip to content

Commit c26a34c

Browse files
nodejs-github-botjuanarbol
authored andcommitted
deps: update undici to 5.18.0
PR-URL: #46502 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent db93ee4 commit c26a34c

File tree

8 files changed

+202
-12
lines changed

8 files changed

+202
-12
lines changed

deps/undici/src/docs/api/Client.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Furthermore, the following options can be passed:
3838
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
3939
* **timeout** `number | null` (optional) - Default `10e3`
4040
* **servername** `string | null` (optional)
41+
* **keepAlive** `boolean | null` (optional) - Default: `true` - TCP keep-alive enabled
42+
* **keepAliveInitialDelay** `number | null` (optional) - Default: `60000` - TCP keep-alive interval for the socket in milliseconds
4143

4244
### Example - Basic Client instantiation
4345

deps/undici/src/lib/client.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const assert = require('assert')
66
const net = require('net')
77
const util = require('./core/util')
8+
const timers = require('./timers')
89
const Request = require('./core/request')
910
const DispatcherBase = require('./dispatcher-base')
1011
const {
@@ -444,9 +445,9 @@ class Parser {
444445
setTimeout (value, type) {
445446
this.timeoutType = type
446447
if (value !== this.timeoutValue) {
447-
clearTimeout(this.timeout)
448+
timers.clearTimeout(this.timeout)
448449
if (value) {
449-
this.timeout = setTimeout(onParserTimeout, value, this)
450+
this.timeout = timers.setTimeout(onParserTimeout, value, this)
450451
// istanbul ignore else: only for jest
451452
if (this.timeout.unref) {
452453
this.timeout.unref()
@@ -562,7 +563,7 @@ class Parser {
562563
this.llhttp.llhttp_free(this.ptr)
563564
this.ptr = null
564565

565-
clearTimeout(this.timeout)
566+
timers.clearTimeout(this.timeout)
566567
this.timeout = null
567568
this.timeoutValue = null
568569
this.timeoutType = null

deps/undici/src/lib/core/connect.js

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ function buildConnector ({ maxCachedSessions, socketPath, timeout, ...opts }) {
120120
})
121121
}
122122

123+
// Set TCP keep alive options on the socket here instead of in connect() for the case of assigning the socket
124+
if (options.keepAlive == null || options.keepAlive) {
125+
const keepAliveInitialDelay = options.keepAliveInitialDelay === undefined ? 60e3 : options.keepAliveInitialDelay
126+
socket.setKeepAlive(true, keepAliveInitialDelay)
127+
}
128+
123129
const cancelTimeout = setupTimeout(() => onConnectTimeout(socket), timeout)
124130

125131
socket

deps/undici/src/lib/core/request.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,13 @@ class Request {
279279
}
280280

281281
function processHeaderValue (key, val) {
282-
if (val && (typeof val === 'object' && !Array.isArray(val))) {
282+
if (val && typeof val === 'object') {
283283
throw new InvalidArgumentError(`invalid ${key} header`)
284-
} else if (headerCharRegex.exec(val) !== null) {
284+
}
285+
286+
val = val != null ? `${val}` : ''
287+
288+
if (headerCharRegex.exec(val) !== null) {
285289
throw new InvalidArgumentError(`invalid ${key} header`)
286290
}
287291

deps/undici/src/lib/timers.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
'use strict'
2+
3+
let fastNow = Date.now()
4+
let fastNowTimeout
5+
6+
const fastTimers = []
7+
8+
function onTimeout () {
9+
fastNow = Date.now()
10+
11+
let len = fastTimers.length
12+
let idx = 0
13+
while (idx < len) {
14+
const timer = fastTimers[idx]
15+
16+
if (timer.expires && fastNow >= timer.expires) {
17+
timer.expires = 0
18+
timer.callback(timer.opaque)
19+
}
20+
21+
if (timer.expires === 0) {
22+
timer.active = false
23+
if (idx !== len - 1) {
24+
fastTimers[idx] = fastTimers.pop()
25+
} else {
26+
fastTimers.pop()
27+
}
28+
len -= 1
29+
} else {
30+
idx += 1
31+
}
32+
}
33+
34+
if (fastTimers.length > 0) {
35+
refreshTimeout()
36+
}
37+
}
38+
39+
function refreshTimeout () {
40+
if (fastNowTimeout && fastNowTimeout.refresh) {
41+
fastNowTimeout.refresh()
42+
} else {
43+
clearTimeout(fastNowTimeout)
44+
fastNowTimeout = setTimeout(onTimeout, 1e3)
45+
if (fastNowTimeout.unref) {
46+
fastNowTimeout.unref()
47+
}
48+
}
49+
}
50+
51+
class Timeout {
52+
constructor (callback, delay, opaque) {
53+
this.callback = callback
54+
this.delay = delay
55+
this.opaque = opaque
56+
this.expires = 0
57+
this.active = false
58+
59+
this.refresh()
60+
}
61+
62+
refresh () {
63+
if (!this.active) {
64+
this.active = true
65+
fastTimers.push(this)
66+
if (!fastNowTimeout || fastTimers.length === 1) {
67+
refreshTimeout()
68+
fastNow = Date.now()
69+
}
70+
}
71+
72+
this.expires = fastNow + this.delay
73+
}
74+
75+
clear () {
76+
this.expires = 0
77+
}
78+
}
79+
80+
module.exports = {
81+
setTimeout (callback, delay, opaque) {
82+
return new Timeout(callback, delay, opaque)
83+
},
84+
clearTimeout (timeout) {
85+
if (timeout && timeout.clear) {
86+
timeout.clear()
87+
}
88+
}
89+
}

deps/undici/src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "undici",
3-
"version": "5.17.1",
3+
"version": "5.18.0",
44
"description": "An HTTP/1.1 client, written from scratch for Node.js",
55
"homepage": "https://undici.nodejs.org",
66
"bugs": {

deps/undici/undici.js

+93-5
Original file line numberDiff line numberDiff line change
@@ -7843,6 +7843,87 @@ var require_pool_base = __commonJS({
78437843
}
78447844
});
78457845

7846+
// lib/timers.js
7847+
var require_timers = __commonJS({
7848+
"lib/timers.js"(exports2, module2) {
7849+
"use strict";
7850+
var fastNow = Date.now();
7851+
var fastNowTimeout;
7852+
var fastTimers = [];
7853+
function onTimeout() {
7854+
fastNow = Date.now();
7855+
let len = fastTimers.length;
7856+
let idx = 0;
7857+
while (idx < len) {
7858+
const timer = fastTimers[idx];
7859+
if (timer.expires && fastNow >= timer.expires) {
7860+
timer.expires = 0;
7861+
timer.callback(timer.opaque);
7862+
}
7863+
if (timer.expires === 0) {
7864+
timer.active = false;
7865+
if (idx !== len - 1) {
7866+
fastTimers[idx] = fastTimers.pop();
7867+
} else {
7868+
fastTimers.pop();
7869+
}
7870+
len -= 1;
7871+
} else {
7872+
idx += 1;
7873+
}
7874+
}
7875+
if (fastTimers.length > 0) {
7876+
refreshTimeout();
7877+
}
7878+
}
7879+
function refreshTimeout() {
7880+
if (fastNowTimeout && fastNowTimeout.refresh) {
7881+
fastNowTimeout.refresh();
7882+
} else {
7883+
clearTimeout(fastNowTimeout);
7884+
fastNowTimeout = setTimeout(onTimeout, 1e3);
7885+
if (fastNowTimeout.unref) {
7886+
fastNowTimeout.unref();
7887+
}
7888+
}
7889+
}
7890+
var Timeout = class {
7891+
constructor(callback, delay, opaque) {
7892+
this.callback = callback;
7893+
this.delay = delay;
7894+
this.opaque = opaque;
7895+
this.expires = 0;
7896+
this.active = false;
7897+
this.refresh();
7898+
}
7899+
refresh() {
7900+
if (!this.active) {
7901+
this.active = true;
7902+
fastTimers.push(this);
7903+
if (!fastNowTimeout || fastTimers.length === 1) {
7904+
refreshTimeout();
7905+
fastNow = Date.now();
7906+
}
7907+
}
7908+
this.expires = fastNow + this.delay;
7909+
}
7910+
clear() {
7911+
this.expires = 0;
7912+
}
7913+
};
7914+
module2.exports = {
7915+
setTimeout(callback, delay, opaque) {
7916+
return new Timeout(callback, delay, opaque);
7917+
},
7918+
clearTimeout(timeout) {
7919+
if (timeout && timeout.clear) {
7920+
timeout.clear();
7921+
}
7922+
}
7923+
};
7924+
}
7925+
});
7926+
78467927
// lib/core/request.js
78477928
var require_request2 = __commonJS({
78487929
"lib/core/request.js"(exports2, module2) {
@@ -8051,9 +8132,11 @@ var require_request2 = __commonJS({
80518132
}
80528133
};
80538134
function processHeaderValue(key, val) {
8054-
if (val && (typeof val === "object" && !Array.isArray(val))) {
8135+
if (val && typeof val === "object") {
80558136
throw new InvalidArgumentError(`invalid ${key} header`);
8056-
} else if (headerCharRegex.exec(val) !== null) {
8137+
}
8138+
val = val != null ? `${val}` : "";
8139+
if (headerCharRegex.exec(val) !== null) {
80578140
throw new InvalidArgumentError(`invalid ${key} header`);
80588141
}
80598142
return `${key}: ${val}\r
@@ -8204,6 +8287,10 @@ var require_connect = __commonJS({
82048287
host: hostname
82058288
});
82068289
}
8290+
if (options.keepAlive == null || options.keepAlive) {
8291+
const keepAliveInitialDelay = options.keepAliveInitialDelay === void 0 ? 6e4 : options.keepAliveInitialDelay;
8292+
socket.setKeepAlive(true, keepAliveInitialDelay);
8293+
}
82078294
const cancelTimeout = setupTimeout(() => onConnectTimeout(socket), timeout);
82088295
socket.setNoDelay(true).once(protocol === "https:" ? "secureConnect" : "connect", function() {
82098296
cancelTimeout();
@@ -8774,6 +8861,7 @@ var require_client = __commonJS({
87748861
var assert = require("assert");
87758862
var net = require("net");
87768863
var util = require_util();
8864+
var timers = require_timers();
87778865
var Request = require_request2();
87788866
var DispatcherBase = require_dispatcher_base();
87798867
var {
@@ -9130,9 +9218,9 @@ var require_client = __commonJS({
91309218
setTimeout(value, type) {
91319219
this.timeoutType = type;
91329220
if (value !== this.timeoutValue) {
9133-
clearTimeout(this.timeout);
9221+
timers.clearTimeout(this.timeout);
91349222
if (value) {
9135-
this.timeout = setTimeout(onParserTimeout, value, this);
9223+
this.timeout = timers.setTimeout(onParserTimeout, value, this);
91369224
if (this.timeout.unref) {
91379225
this.timeout.unref();
91389226
}
@@ -9221,7 +9309,7 @@ var require_client = __commonJS({
92219309
assert(currentParser == null);
92229310
this.llhttp.llhttp_free(this.ptr);
92239311
this.ptr = null;
9224-
clearTimeout(this.timeout);
9312+
timers.clearTimeout(this.timeout);
92259313
this.timeout = null;
92269314
this.timeoutValue = null;
92279315
this.timeoutType = null;

src/undici_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/update-undici.sh
33
#ifndef SRC_UNDICI_VERSION_H_
44
#define SRC_UNDICI_VERSION_H_
5-
#define UNDICI_VERSION "5.17.1"
5+
#define UNDICI_VERSION "5.18.0"
66
#endif // SRC_UNDICI_VERSION_H_

0 commit comments

Comments
 (0)