Skip to content

Commit d128356

Browse files
nodejs-github-botBethGriggs
authored andcommitted
deps: update undici to 5.2.0
PR-URL: #43059 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent cec678a commit d128356

14 files changed

+256
-224
lines changed

deps/undici/src/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ Basic usage example:
194194
}
195195
```
196196

197+
You can pass an optional dispatcher to `fetch` as:
198+
199+
```js
200+
import { fetch, Agent } from 'undici'
201+
202+
const res = await fetch('https://example.com', {
203+
// Mocks are also supported
204+
dispatcher: new Agent({
205+
keepAliveTimeout: 10,
206+
keepAliveMaxTimeout: 10
207+
})
208+
})
209+
const json = await res.json()
210+
console.log(json)
211+
```
197212

198213
#### `request.body`
199214

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

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { errors } from 'undici'
1919
| `RequestContentLengthMismatchError` | `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` | request body does not match content-length header |
2020
| `ResponseContentLengthMismatchError` | `UND_ERR_RES_CONTENT_LENGTH_MISMATCH` | response body does not match content-length header |
2121
| `InformationalError` | `UND_ERR_INFO` | expected error with reason |
22-
| `TrailerMismatchError` | `UND_ERR_TRAILER_MISMATCH` | trailers did not match specification |
2322

2423
### `SocketError`
2524

deps/undici/src/index-fetch.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use strict'
22

3-
const Agent = require('./lib/agent')
4-
5-
const globalDispatcher = new Agent()
6-
3+
const { getGlobalDispatcher } = require('./lib/global')
74
const fetchImpl = require('./lib/fetch')
5+
86
module.exports.fetch = async function fetch (resource) {
9-
return fetchImpl.apply(globalDispatcher, arguments)
7+
const dispatcher = (arguments[1] && arguments[1].dispatcher) || getGlobalDispatcher()
8+
return fetchImpl.apply(dispatcher, arguments)
109
}
1110
module.exports.FormData = require('./lib/fetch/formdata').FormData
1211
module.exports.Headers = require('./lib/fetch/headers').Headers

deps/undici/src/index.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const MockAgent = require('./lib/mock/mock-agent')
1515
const MockPool = require('./lib/mock/mock-pool')
1616
const mockErrors = require('./lib/mock/mock-errors')
1717
const ProxyAgent = require('./lib/proxy-agent')
18+
const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
1819

1920
const nodeVersion = process.versions.node.split('.')
2021
const nodeMajor = Number(nodeVersion[0])
@@ -32,19 +33,6 @@ module.exports.ProxyAgent = ProxyAgent
3233
module.exports.buildConnector = buildConnector
3334
module.exports.errors = errors
3435

35-
let globalDispatcher = new Agent()
36-
37-
function setGlobalDispatcher (agent) {
38-
if (!agent || typeof agent.dispatch !== 'function') {
39-
throw new InvalidArgumentError('Argument agent must implement Agent')
40-
}
41-
globalDispatcher = agent
42-
}
43-
44-
function getGlobalDispatcher () {
45-
return globalDispatcher
46-
}
47-
4836
function makeDispatcher (fn) {
4937
return (url, opts, handler) => {
5038
if (typeof opts === 'function') {
@@ -98,7 +86,7 @@ if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 5)) {
9886
if (!fetchImpl) {
9987
fetchImpl = require('./lib/fetch')
10088
}
101-
const dispatcher = getGlobalDispatcher()
89+
const dispatcher = (arguments[1] && arguments[1].dispatcher) || getGlobalDispatcher()
10290
return fetchImpl.apply(dispatcher, arguments)
10391
}
10492
module.exports.Headers = require('./lib/fetch/headers').Headers

deps/undici/src/lib/client.js

+1-23
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const RedirectHandler = require('./handler/redirect')
1111
const {
1212
RequestContentLengthMismatchError,
1313
ResponseContentLengthMismatchError,
14-
TrailerMismatchError,
1514
InvalidArgumentError,
1615
RequestAbortedError,
1716
HeadersTimeoutError,
@@ -425,7 +424,6 @@ class Parser {
425424

426425
this.bytesRead = 0
427426

428-
this.trailer = ''
429427
this.keepAlive = ''
430428
this.contentLength = ''
431429
}
@@ -615,8 +613,6 @@ class Parser {
615613
const key = this.headers[len - 2]
616614
if (key.length === 10 && key.toString().toLowerCase() === 'keep-alive') {
617615
this.keepAlive += buf.toString()
618-
} else if (key.length === 7 && key.toString().toLowerCase() === 'trailer') {
619-
this.trailer += buf.toString()
620616
} else if (key.length === 14 && key.toString().toLowerCase() === 'content-length') {
621617
this.contentLength += buf.toString()
622618
}
@@ -819,7 +815,7 @@ class Parser {
819815
}
820816

821817
onMessageComplete () {
822-
const { client, socket, statusCode, upgrade, trailer, headers, contentLength, bytesRead, shouldKeepAlive } = this
818+
const { client, socket, statusCode, upgrade, headers, contentLength, bytesRead, shouldKeepAlive } = this
823819

824820
if (socket.destroyed && (!statusCode || shouldKeepAlive)) {
825821
return -1
@@ -838,7 +834,6 @@ class Parser {
838834
this.statusText = ''
839835
this.bytesRead = 0
840836
this.contentLength = ''
841-
this.trailer = ''
842837
this.keepAlive = ''
843838

844839
assert(this.headers.length % 2 === 0)
@@ -849,23 +844,6 @@ class Parser {
849844
return
850845
}
851846

852-
const trailers = trailer ? trailer.split(/,\s*/) : []
853-
for (let i = 0; i < trailers.length; i++) {
854-
const trailer = trailers[i]
855-
let found = false
856-
for (let n = 0; n < headers.length; n += 2) {
857-
const key = headers[n]
858-
if (key.length === trailer.length && key.toString().toLowerCase() === trailer.toLowerCase()) {
859-
found = true
860-
break
861-
}
862-
}
863-
if (!found) {
864-
util.destroy(socket, new TrailerMismatchError())
865-
return -1
866-
}
867-
}
868-
869847
/* istanbul ignore next: should be handled by llhttp? */
870848
if (request.method !== 'HEAD' && contentLength && bytesRead !== parseInt(contentLength, 10)) {
871849
util.destroy(socket, new ResponseContentLengthMismatchError())

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

-11
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ class ResponseContentLengthMismatchError extends UndiciError {
116116
}
117117
}
118118

119-
class TrailerMismatchError extends UndiciError {
120-
constructor (message) {
121-
super(message)
122-
Error.captureStackTrace(this, TrailerMismatchError)
123-
this.name = 'TrailerMismatchError'
124-
this.message = message || 'Trailers does not match trailer header'
125-
this.code = 'UND_ERR_TRAILER_MISMATCH'
126-
}
127-
}
128-
129119
class ClientDestroyedError extends UndiciError {
130120
constructor (message) {
131121
super(message)
@@ -196,7 +186,6 @@ module.exports = {
196186
BodyTimeoutError,
197187
RequestContentLengthMismatchError,
198188
ConnectTimeoutError,
199-
TrailerMismatchError,
200189
InvalidArgumentError,
201190
InvalidReturnValueError,
202191
RequestAbortedError,

0 commit comments

Comments
 (0)