Skip to content

Commit

Permalink
deps: update undici to 5.2.0
Browse files Browse the repository at this point in the history
PR-URL: #43059
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
nodejs-github-bot authored and targos committed Jul 12, 2022
1 parent 0bdb5f2 commit 7f1f217
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 224 deletions.
15 changes: 15 additions & 0 deletions deps/undici/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ Basic usage example:
}
```

You can pass an optional dispatcher to `fetch` as:

```js
import { fetch, Agent } from 'undici'

const res = await fetch('https://example.com', {
// Mocks are also supported
dispatcher: new Agent({
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10
})
})
const json = await res.json()
console.log(json)
```

#### `request.body`

Expand Down
1 change: 0 additions & 1 deletion deps/undici/src/docs/api/Errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { errors } from 'undici'
| `RequestContentLengthMismatchError` | `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` | request body does not match content-length header |
| `ResponseContentLengthMismatchError` | `UND_ERR_RES_CONTENT_LENGTH_MISMATCH` | response body does not match content-length header |
| `InformationalError` | `UND_ERR_INFO` | expected error with reason |
| `TrailerMismatchError` | `UND_ERR_TRAILER_MISMATCH` | trailers did not match specification |

### `SocketError`

Expand Down
9 changes: 4 additions & 5 deletions deps/undici/src/index-fetch.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict'

const Agent = require('./lib/agent')

const globalDispatcher = new Agent()

const { getGlobalDispatcher } = require('./lib/global')
const fetchImpl = require('./lib/fetch')

module.exports.fetch = async function fetch (resource) {
return fetchImpl.apply(globalDispatcher, arguments)
const dispatcher = (arguments[1] && arguments[1].dispatcher) || getGlobalDispatcher()
return fetchImpl.apply(dispatcher, arguments)
}
module.exports.FormData = require('./lib/fetch/formdata').FormData
module.exports.Headers = require('./lib/fetch/headers').Headers
Expand Down
16 changes: 2 additions & 14 deletions deps/undici/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MockAgent = require('./lib/mock/mock-agent')
const MockPool = require('./lib/mock/mock-pool')
const mockErrors = require('./lib/mock/mock-errors')
const ProxyAgent = require('./lib/proxy-agent')
const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')

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

let globalDispatcher = new Agent()

function setGlobalDispatcher (agent) {
if (!agent || typeof agent.dispatch !== 'function') {
throw new InvalidArgumentError('Argument agent must implement Agent')
}
globalDispatcher = agent
}

function getGlobalDispatcher () {
return globalDispatcher
}

function makeDispatcher (fn) {
return (url, opts, handler) => {
if (typeof opts === 'function') {
Expand Down Expand Up @@ -98,7 +86,7 @@ if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 5)) {
if (!fetchImpl) {
fetchImpl = require('./lib/fetch')
}
const dispatcher = getGlobalDispatcher()
const dispatcher = (arguments[1] && arguments[1].dispatcher) || getGlobalDispatcher()
return fetchImpl.apply(dispatcher, arguments)
}
module.exports.Headers = require('./lib/fetch/headers').Headers
Expand Down
24 changes: 1 addition & 23 deletions deps/undici/src/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const RedirectHandler = require('./handler/redirect')
const {
RequestContentLengthMismatchError,
ResponseContentLengthMismatchError,
TrailerMismatchError,
InvalidArgumentError,
RequestAbortedError,
HeadersTimeoutError,
Expand Down Expand Up @@ -425,7 +424,6 @@ class Parser {

this.bytesRead = 0

this.trailer = ''
this.keepAlive = ''
this.contentLength = ''
}
Expand Down Expand Up @@ -615,8 +613,6 @@ class Parser {
const key = this.headers[len - 2]
if (key.length === 10 && key.toString().toLowerCase() === 'keep-alive') {
this.keepAlive += buf.toString()
} else if (key.length === 7 && key.toString().toLowerCase() === 'trailer') {
this.trailer += buf.toString()
} else if (key.length === 14 && key.toString().toLowerCase() === 'content-length') {
this.contentLength += buf.toString()
}
Expand Down Expand Up @@ -819,7 +815,7 @@ class Parser {
}

onMessageComplete () {
const { client, socket, statusCode, upgrade, trailer, headers, contentLength, bytesRead, shouldKeepAlive } = this
const { client, socket, statusCode, upgrade, headers, contentLength, bytesRead, shouldKeepAlive } = this

if (socket.destroyed && (!statusCode || shouldKeepAlive)) {
return -1
Expand All @@ -838,7 +834,6 @@ class Parser {
this.statusText = ''
this.bytesRead = 0
this.contentLength = ''
this.trailer = ''
this.keepAlive = ''

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

const trailers = trailer ? trailer.split(/,\s*/) : []
for (let i = 0; i < trailers.length; i++) {
const trailer = trailers[i]
let found = false
for (let n = 0; n < headers.length; n += 2) {
const key = headers[n]
if (key.length === trailer.length && key.toString().toLowerCase() === trailer.toLowerCase()) {
found = true
break
}
}
if (!found) {
util.destroy(socket, new TrailerMismatchError())
return -1
}
}

/* istanbul ignore next: should be handled by llhttp? */
if (request.method !== 'HEAD' && contentLength && bytesRead !== parseInt(contentLength, 10)) {
util.destroy(socket, new ResponseContentLengthMismatchError())
Expand Down
11 changes: 0 additions & 11 deletions deps/undici/src/lib/core/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,6 @@ class ResponseContentLengthMismatchError extends UndiciError {
}
}

class TrailerMismatchError extends UndiciError {
constructor (message) {
super(message)
Error.captureStackTrace(this, TrailerMismatchError)
this.name = 'TrailerMismatchError'
this.message = message || 'Trailers does not match trailer header'
this.code = 'UND_ERR_TRAILER_MISMATCH'
}
}

class ClientDestroyedError extends UndiciError {
constructor (message) {
super(message)
Expand Down Expand Up @@ -196,7 +186,6 @@ module.exports = {
BodyTimeoutError,
RequestContentLengthMismatchError,
ConnectTimeoutError,
TrailerMismatchError,
InvalidArgumentError,
InvalidReturnValueError,
RequestAbortedError,
Expand Down
Loading

0 comments on commit 7f1f217

Please sign in to comment.