Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 75c7d04

Browse files
nodejs-github-bottargos
authored andcommittedNov 23, 2023
deps: update undici to 5.27.2
PR-URL: #50813 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Matthew Aitken <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6a30eda commit 75c7d04

File tree

12 files changed

+1090
-258
lines changed

12 files changed

+1090
-258
lines changed
 

‎deps/undici/src/lib/client.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -1462,23 +1462,7 @@ function _resume (client, sync) {
14621462
return
14631463
}
14641464

1465-
if (util.isStream(request.body) && util.bodyLength(request.body) === 0) {
1466-
request.body
1467-
.on('data', /* istanbul ignore next */ function () {
1468-
/* istanbul ignore next */
1469-
assert(false)
1470-
})
1471-
.on('error', function (err) {
1472-
errorRequest(client, request, err)
1473-
})
1474-
.on('end', function () {
1475-
util.destroy(this)
1476-
})
1477-
1478-
request.body = null
1479-
}
1480-
1481-
if (client[kRunning] > 0 &&
1465+
if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
14821466
(util.isStream(request.body) || util.isAsyncIterable(request.body))) {
14831467
// Request with stream or iterator body can error while other requests
14841468
// are inflight and indirectly error those as well.
@@ -1499,6 +1483,11 @@ function _resume (client, sync) {
14991483
}
15001484
}
15011485

1486+
// https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2
1487+
function shouldSendContentLength (method) {
1488+
return method !== 'GET' && method !== 'HEAD' && method !== 'OPTIONS' && method !== 'TRACE' && method !== 'CONNECT'
1489+
}
1490+
15021491
function write (client, request) {
15031492
if (client[kHTTPConnVersion] === 'h2') {
15041493
writeH2(client, client[kHTTP2Session], request)
@@ -1527,7 +1516,9 @@ function write (client, request) {
15271516
body.read(0)
15281517
}
15291518

1530-
let contentLength = util.bodyLength(body)
1519+
const bodyLength = util.bodyLength(body)
1520+
1521+
let contentLength = bodyLength
15311522

15321523
if (contentLength === null) {
15331524
contentLength = request.contentLength
@@ -1542,7 +1533,9 @@ function write (client, request) {
15421533
contentLength = null
15431534
}
15441535

1545-
if (request.contentLength !== null && request.contentLength !== contentLength) {
1536+
// https://github.com/nodejs/undici/issues/2046
1537+
// A user agent may send a Content-Length header with 0 value, this should be allowed.
1538+
if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength !== null && request.contentLength !== contentLength) {
15461539
if (client[kStrictContentLength]) {
15471540
errorRequest(client, request, new RequestContentLengthMismatchError())
15481541
return false
@@ -1623,7 +1616,7 @@ function write (client, request) {
16231616
}
16241617

16251618
/* istanbul ignore else: assertion */
1626-
if (!body) {
1619+
if (!body || bodyLength === 0) {
16271620
if (contentLength === 0) {
16281621
socket.write(`${header}content-length: 0\r\n\r\n`, 'latin1')
16291622
} else {
@@ -1763,7 +1756,9 @@ function writeH2 (client, session, request) {
17631756
contentLength = null
17641757
}
17651758

1766-
if (request.contentLength != null && request.contentLength !== contentLength) {
1759+
// https://github.com/nodejs/undici/issues/2046
1760+
// A user agent may send a Content-Length header with 0 value, this should be allowed.
1761+
if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength != null && request.contentLength !== contentLength) {
17671762
if (client[kStrictContentLength]) {
17681763
errorRequest(client, request, new RequestContentLengthMismatchError())
17691764
return false

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

+41-1
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,29 @@ class Request {
112112

113113
this.method = method
114114

115+
this.abort = null
116+
115117
if (body == null) {
116118
this.body = null
117119
} else if (util.isStream(body)) {
118120
this.body = body
121+
122+
const rState = this.body._readableState
123+
if (!rState || !rState.autoDestroy) {
124+
this.endHandler = function autoDestroy () {
125+
util.destroy(this)
126+
}
127+
this.body.on('end', this.endHandler)
128+
}
129+
130+
this.errorHandler = err => {
131+
if (this.abort) {
132+
this.abort(err)
133+
} else {
134+
this.error = err
135+
}
136+
}
137+
this.body.on('error', this.errorHandler)
119138
} else if (util.isBuffer(body)) {
120139
this.body = body.byteLength ? body : null
121140
} else if (ArrayBuffer.isView(body)) {
@@ -236,7 +255,12 @@ class Request {
236255
assert(!this.aborted)
237256
assert(!this.completed)
238257

239-
return this[kHandler].onConnect(abort)
258+
if (this.error) {
259+
abort(this.error)
260+
} else {
261+
this.abort = abort
262+
return this[kHandler].onConnect(abort)
263+
}
240264
}
241265

242266
onHeaders (statusCode, headers, resume, statusText) {
@@ -265,6 +289,8 @@ class Request {
265289
}
266290

267291
onComplete (trailers) {
292+
this.onFinally()
293+
268294
assert(!this.aborted)
269295

270296
this.completed = true
@@ -275,6 +301,8 @@ class Request {
275301
}
276302

277303
onError (error) {
304+
this.onFinally()
305+
278306
if (channels.error.hasSubscribers) {
279307
channels.error.publish({ request: this, error })
280308
}
@@ -286,6 +314,18 @@ class Request {
286314
return this[kHandler].onError(error)
287315
}
288316

317+
onFinally () {
318+
if (this.errorHandler) {
319+
this.body.off('error', this.errorHandler)
320+
this.errorHandler = null
321+
}
322+
323+
if (this.endHandler) {
324+
this.body.off('end', this.endHandler)
325+
this.endHandler = null
326+
}
327+
}
328+
289329
// TODO: adjust to support H2
290330
addHeader (key, value) {
291331
processHeader(this, key, value)

‎deps/undici/src/lib/core/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function isReadableAborted (stream) {
190190
}
191191

192192
function destroy (stream, err) {
193-
if (!isStream(stream) || isDestroyed(stream)) {
193+
if (stream == null || !isStream(stream) || isDestroyed(stream)) {
194194
return
195195
}
196196

‎deps/undici/src/lib/pool.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Pool extends PoolBase {
5757
maxCachedSessions,
5858
allowH2,
5959
socketPath,
60-
timeout: connectTimeout == null ? 10e3 : connectTimeout,
60+
timeout: connectTimeout,
6161
...(util.nodeHasAutoSelectFamily && autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
6262
...connect
6363
})

‎deps/undici/src/node_modules/@fastify/busboy/lib/utils/decodeText.js

+97-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deps/undici/src/node_modules/@fastify/busboy/lib/utils/parseParams.js

+122-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deps/undici/src/node_modules/@fastify/busboy/package.json

+5-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deps/undici/src/package-lock.json

+163-150
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎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.27.0",
3+
"version": "5.27.2",
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

+639-49
Large diffs are not rendered by default.

‎doc/contributing/maintaining/maintaining-dependencies.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This a list of all the dependencies:
2929
* [postject 1.0.0-alpha.6][]
3030
* [simdjson 3.6.0][]
3131
* [simdutf 4.0.4][]
32-
* [undici 5.27.0][]
32+
* [undici 5.27.2][]
3333
* [uvwasi 0.0.19][]
3434
* [V8 11.8.172.12][]
3535
* [zlib 1.2.13.1-motley-dfc48fc][]
@@ -297,7 +297,7 @@ a C++ library for fast JSON parsing.
297297
The [simdutf](https://github.com/simdutf/simdutf) dependency is
298298
a C++ library for fast UTF-8 decoding and encoding.
299299

300-
### undici 5.27.0
300+
### undici 5.27.2
301301

302302
The [undici](https://github.com/nodejs/undici) dependency is an HTTP/1.1 client,
303303
written from scratch for Node.js..
@@ -352,7 +352,7 @@ performance improvements not currently available in standard zlib.
352352
[postject 1.0.0-alpha.6]: #postject-100-alpha6
353353
[simdjson 3.6.0]: #simdutf-360
354354
[simdutf 4.0.4]: #simdutf-404
355-
[undici 5.27.0]: #undici-5270
355+
[undici 5.27.2]: #undici-5272
356356
[update-openssl-action]: ../../../.github/workflows/update-openssl.yml
357357
[uvwasi 0.0.19]: #uvwasi-0019
358358
[v8 11.8.172.12]: #v8-11817212

‎src/undici_version.h

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

0 commit comments

Comments
 (0)
Please sign in to comment.