mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
deps: update undici to 8.13.1
PR-URL: https://github.com/nodejs/node/pull/67692 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
d9540f53db
commit
f230732dec
41 files changed
+1390
-568
No files matched your search
Vendored
+76
-32
@@ -36,6 +36,29 @@ issue.
|
||||
|
||||
Undici is an HTTP client library for Node.js. Its threat model is derived from
|
||||
and aligned with the [Node.js threat model](https://github.com/nodejs/node/blob/HEAD/SECURITY.md#the-nodejs-threat-model).
|
||||
The Node.js policy is authoritative for the copy of undici bundled with
|
||||
Node.js. This section applies the same boundaries to the standalone undici
|
||||
package.
|
||||
|
||||
### Security triage dispositions
|
||||
|
||||
Security reports are classified using the same dispositions as Node.js:
|
||||
|
||||
* **Vulnerability**: An undici defect that is exploitable across an
|
||||
undici-owned security boundary and meets the criteria under
|
||||
[What constitutes a vulnerability](#what-constitutes-a-vulnerability),
|
||||
including any applicable DoS criteria.
|
||||
* **Security-interest bug**: A real undici defect, or an API behavior likely to
|
||||
cause security bugs in applications, that is not itself a vulnerability
|
||||
under this threat model. These are fixed as regular bugs and do not
|
||||
automatically receive a CVE, but should still be reported privately first
|
||||
when they affect a common security control such as protocol interpretation,
|
||||
certificate validation, or TLS decisions.
|
||||
* **Common bug**: A correctness, robustness, or crash issue without an
|
||||
undici-owned security boundary or a realistic cross-boundary attacker
|
||||
benefit.
|
||||
* **Invalid / out of scope**: A report that cannot be reproduced, is not an
|
||||
undici defect, or concerns behavior excluded by this policy.
|
||||
|
||||
### What constitutes a vulnerability
|
||||
|
||||
@@ -53,27 +76,40 @@ For a behavior to be considered a DoS vulnerability, the proof of concept must
|
||||
meet the following criteria:
|
||||
|
||||
* The API is being correctly used.
|
||||
* The API is public and documented.
|
||||
* The behavior is significant enough to cause a denial of service quickly
|
||||
or in a context not controlled by the application developer (for example,
|
||||
HTTP parsing).
|
||||
* The API does not have a warning against its use in production.
|
||||
* The API is public and documented. For standards-based APIs, the behavior
|
||||
must be well-defined by the applicable specification.
|
||||
* The API is stable. For APIs bundled in Node.js, it must have stable (2.0)
|
||||
status.
|
||||
* The behavior is significant enough to cause a denial of service quickly or
|
||||
in a context not controlled by the application developer, such as protocol
|
||||
parsing.
|
||||
* The behavior is directly exploitable by an untrusted source without requiring
|
||||
application mistakes.
|
||||
* The behavior cannot be reasonably mitigated through standard operational
|
||||
practices (like process recycling).
|
||||
practices, such as process recycling.
|
||||
* The behavior occurs deterministically under normal usage patterns rather than
|
||||
only in edge cases.
|
||||
* The behavior occurs at a rate that would cause practical resource exhaustion
|
||||
within a practical timeframe under typical workloads.
|
||||
* The attack demonstrates
|
||||
[asymmetric resource consumption](https://cwe.mitre.org/data/definitions/405.html),
|
||||
where the attacker expends significantly fewer resources than what is required
|
||||
by the client to process the attack.
|
||||
where the attacker expends significantly fewer resources than the client
|
||||
must expend to process the attack. Attacks requiring comparable resources on
|
||||
the attacker's side, which can be mitigated through practices such as rate
|
||||
limiting, may not qualify.
|
||||
|
||||
**Undici does NOT trust**:
|
||||
|
||||
* Data received from the remote end of HTTP connections (both inbound responses
|
||||
and server-sent data) that is parsed or transformed by undici before being
|
||||
passed to the application. This includes:
|
||||
* Data received from the remote end of outbound network connections created
|
||||
through undici APIs and transformed or validated by undici before being
|
||||
passed to the application, **except with respect to payload length**. Undici
|
||||
trusts applications to make connections and requests that avoid payload
|
||||
sizes that would result in a denial of service. Subject to that exception,
|
||||
untrusted data includes:
|
||||
* HTTP response headers and status lines.
|
||||
* HTTP response bodies when processed by undici (e.g., chunked transfer
|
||||
decoding, content-encoding).
|
||||
* HTTP response bodies processed by undici, such as chunked transfer decoding
|
||||
and content-encoding.
|
||||
* WebSocket frames received from a server.
|
||||
* Server-Sent Events (EventSource) data received from a server.
|
||||
* TLS certificate validation performed by undici on behalf of the application.
|
||||
@@ -81,7 +117,8 @@ meet the following criteria:
|
||||
**Undici trusts**:
|
||||
|
||||
* The application code that uses its APIs, including all configuration,
|
||||
options, callbacks, and decisions about which body-consuming APIs to call.
|
||||
options, callbacks, connection and request decisions, and decisions about
|
||||
which body-consuming APIs to call.
|
||||
* The operating system and its network stack.
|
||||
* The Node.js runtime undici is running on.
|
||||
* Dependencies installed by the application.
|
||||
@@ -99,19 +136,19 @@ meet the following criteria:
|
||||
bypass organizational, regulatory, or legal controls. Untrusted proxies are
|
||||
outside the supported threat model.
|
||||
|
||||
In other words, if untrusted data passing through undici to the application
|
||||
can trigger actions other than those documented for the APIs, there is likely
|
||||
a security vulnerability. Examples of unwanted actions are polluting globals,
|
||||
causing an unrecoverable crash, or any other unexpected side effects that can
|
||||
lead to a loss of confidentiality, integrity, or availability.
|
||||
In other words, if untrusted data passing through undici to the application can
|
||||
trigger actions other than those documented for the APIs, there is likely a
|
||||
security vulnerability. Examples include polluting globals, causing an
|
||||
unrecoverable crash, or other unexpected side effects that can lead to a loss
|
||||
of confidentiality, integrity, or availability.
|
||||
|
||||
### Examples of vulnerabilities
|
||||
|
||||
#### Improper Certificate Validation (CWE-295)
|
||||
|
||||
* Undici provides TLS connections to HTTPS endpoints. If certificates can be
|
||||
crafted that result in incorrect validation by undici, that is considered
|
||||
a vulnerability.
|
||||
crafted that result in incorrect validation by undici, that is considered a
|
||||
vulnerability.
|
||||
|
||||
#### Inconsistent Interpretation of HTTP Responses (CWE-444)
|
||||
|
||||
@@ -127,12 +164,19 @@ lead to a loss of confidentiality, integrity, or availability.
|
||||
|
||||
#### CRLF Injection in Request Headers (CWE-93)
|
||||
|
||||
* If untrusted input passed to undici APIs (such as header values or URLs)
|
||||
can inject additional headers or corrupt the HTTP request stream, that is
|
||||
* If untrusted input passed to undici APIs, such as header values or URLs, can
|
||||
inject additional headers or corrupt the HTTP request stream, that is
|
||||
considered a vulnerability.
|
||||
|
||||
### Examples of non-vulnerabilities
|
||||
|
||||
#### Defense-in-depth issues
|
||||
|
||||
* Bugs whose fixes only improve resilience after another security boundary has
|
||||
already failed, or reduce the impact of behavior outside this threat model,
|
||||
are defense-in-depth issues. They are fixed as regular bugs and do not
|
||||
receive CVEs.
|
||||
|
||||
#### Malicious Third-Party Modules (CWE-1357)
|
||||
|
||||
* Application code and its dependencies are trusted by undici. Any scenario
|
||||
@@ -141,17 +185,17 @@ lead to a loss of confidentiality, integrity, or availability.
|
||||
|
||||
#### Prototype Pollution Attacks (CWE-1321)
|
||||
|
||||
* Undici trusts the inputs provided to it by application code. It is up to the
|
||||
application to sanitize appropriately. Any scenario that requires control
|
||||
over user input passed directly by the application is not considered a
|
||||
vulnerability in undici.
|
||||
* Undici trusts inputs provided by application code. The application must
|
||||
sanitize them appropriately. A scenario that requires control over user input
|
||||
passed directly by the application is not a vulnerability in undici.
|
||||
|
||||
#### Uncontrolled Resource Consumption on Outbound Connections (CWE-400)
|
||||
|
||||
* If undici is asked to connect to a remote site and the response payload is
|
||||
large enough to impact performance or cause the runtime to run out of
|
||||
resources, that is not considered a vulnerability. Applications are
|
||||
responsible for setting appropriate limits on response sizes.
|
||||
* If undici is asked to connect to a remote site and return an artifact, it is
|
||||
not a vulnerability if the size of that artifact is large enough to impact
|
||||
performance or cause the runtime to run out of resources. Applications are
|
||||
responsible for choosing suitable response-processing APIs and enforcing
|
||||
limits appropriate for their workloads.
|
||||
|
||||
#### Calling body-consuming methods on untrusted responses
|
||||
|
||||
@@ -188,9 +232,9 @@ lead to a loss of confidentiality, integrity, or availability.
|
||||
|
||||
#### Application Misconfiguration
|
||||
|
||||
* Issues arising from incorrect or insecure use of undici APIs (such as
|
||||
* Issues arising from incorrect or insecure use of undici APIs, such as
|
||||
disabling TLS verification, ignoring errors, or passing unsanitized user
|
||||
input to request options) are the application's responsibility, not
|
||||
input to request options, are the application's responsibility and not
|
||||
vulnerabilities in undici.
|
||||
|
||||
#### Unauthorized or untrusted proxy use
|
||||
|
||||
+11
@@ -203,6 +203,16 @@ added: v7.0.0
|
||||
integers; a `TypeError` is thrown otherwise, or if `maxEntrySize` is greater
|
||||
than 2 GB.
|
||||
|
||||
The database is not encrypted, and nothing in it is hashed. The request URL
|
||||
(including the query string), the response headers and body, and the values of
|
||||
any request headers named in the response's `Vary` header (for example
|
||||
`Authorization` or `Cookie`) are written as plain text to `location`. Protect
|
||||
that file like any other sensitive data, or use `':memory:'`. A response to a
|
||||
request that carries `Authorization` is only stored when the response allows it
|
||||
with `public`, `s-maxage`, or `must-revalidate` (see [RFC 9111, Section 3.5][]);
|
||||
servers can send `Cache-Control: no-store` to keep a response out of the cache
|
||||
entirely.
|
||||
|
||||
### `sqliteCacheStore.close()`
|
||||
|
||||
<!-- YAML
|
||||
@@ -372,4 +382,5 @@ The value returned by `get`. It contains every field of
|
||||
body. (optional)
|
||||
|
||||
[RFC 9111]: https://www.rfc-editor.org/rfc/rfc9111.html
|
||||
[RFC 9111, Section 3.5]: https://www.rfc-editor.org/rfc/rfc9111.html#section-3.5
|
||||
[`node:sqlite`]: https://nodejs.org/api/sqlite.html
|
||||
+4
-2
@@ -137,7 +137,9 @@ added: v1.0.0
|
||||
positive integer. **Default:** `524288`.
|
||||
* `pingInterval` {number} The time interval, in milliseconds, between HTTP/2
|
||||
PING frames. Set to `0` to disable PING frames. Applies only to HTTP/2
|
||||
connections and emits a `ping` event on the client. **Default:** `60e3`.
|
||||
connections and emits a `ping` event on the client. A connection whose
|
||||
PING is still unacknowledged when the next one is due is closed, and new
|
||||
requests go to a new connection. **Default:** `60e3`.
|
||||
* `settings` {object} `SETTINGS` frame options. For full reference, take a
|
||||
look to [HTTP/2#Settings Object](https://nodejs.org/api/http2.html#settings-object)
|
||||
* `webSocket` {Object} (optional) WebSocket-specific configuration.
|
||||
@@ -217,7 +219,7 @@ import { Client, buildConnector } from 'undici'
|
||||
const connector = buildConnector({ rejectUnauthorized: false })
|
||||
const client = new Client('https://localhost:3000', {
|
||||
connect (opts, cb) {
|
||||
connector(opts, (err, socket) => {
|
||||
return connector(opts, (err, socket) => {
|
||||
if (err) {
|
||||
cb(err)
|
||||
} else {
|
||||
|
||||
+9
-2
@@ -78,7 +78,7 @@ const connector = buildConnector({ rejectUnauthorized: false })
|
||||
|
||||
const client = new Client('https://localhost:3000', {
|
||||
connect (opts, cb) {
|
||||
connector(opts, (err, socket) => {
|
||||
return connector(opts, (err, socket) => {
|
||||
if (err) {
|
||||
cb(err)
|
||||
} else if (/* assertion */ false) {
|
||||
@@ -124,6 +124,13 @@ targets or a [`tls.TLSSocket`][] for `https:` targets, applies TCP keep-alive an
|
||||
the connect timeout, and invokes `callback` once the socket connects or errors.
|
||||
The socket is also returned synchronously.
|
||||
|
||||
undici uses the returned socket to cancel a connection attempt that no request
|
||||
needs any more: once every request waiting for it is aborted, the socket is
|
||||
destroyed and the next request opens a new connection instead of waiting for
|
||||
it. A connector that wraps another one should return the socket it gets back,
|
||||
as the examples on this page do. If it returns nothing, the attempt runs until
|
||||
it connects or fails.
|
||||
|
||||
When connecting over TLS, established sessions are cached (subject to
|
||||
`maxCachedSessions`) and reused for subsequent connections to the same
|
||||
`servername` or `hostname`.
|
||||
@@ -141,7 +148,7 @@ const connector = buildConnector({ rejectUnauthorized: false })
|
||||
|
||||
const client = new Client('https://localhost:3000', {
|
||||
connect (opts, cb) {
|
||||
connector(opts, (err, socket) => {
|
||||
return connector(opts, (err, socket) => {
|
||||
if (err) {
|
||||
cb(err)
|
||||
} else if (getIssuerCertificate(socket).fingerprint256 !== caFingerprint) {
|
||||
|
||||
+20
@@ -705,6 +705,26 @@ The order of the interceptors matters: the last interceptor in the chain is the
|
||||
first to be called. Forking the chain of interceptors can lead to unexpected
|
||||
results.
|
||||
|
||||
Because interceptors wrap each other, ordering is the end-user's responsibility.
|
||||
Certain built-in interceptors are order-sensitive and will throw an
|
||||
`InvalidArgumentError` if composed in an unsafe order. In particular, the
|
||||
`cache` interceptor must be composed **after** the `redirect` interceptor. When
|
||||
`cache` is composed before `redirect`, the cache handler is wrapped *above* the
|
||||
redirect handler, so it never observes the redirect history and its
|
||||
cross-origin / credential-bearing redirect guards are silently disabled.
|
||||
This allows an attacker-controlled or cross-principal redirect response to be
|
||||
stored under the trusted origin's cache key and replayed to unrelated callers
|
||||
(see GHSA-75VM-9G8F-99J4, GHSA-MQG3-3V4R-CM32, GHSA-4W7W-5XRC-9H26 and
|
||||
GHSA-7XG3-FPHP-28HG).
|
||||
|
||||
```js
|
||||
// Correct: cache is composed after redirect.
|
||||
new Agent().compose(interceptors.redirect({ maxRedirections: 5 }), interceptors.cache({}))
|
||||
|
||||
// Throws an InvalidArgumentError: cache composed before redirect.
|
||||
new Agent().compose(interceptors.cache({}), interceptors.redirect({ maxRedirections: 5 }))
|
||||
```
|
||||
|
||||
```text
|
||||
compose([interceptor1, interceptor2, interceptor3])
|
||||
|
||||
|
||||
+13
-3
@@ -204,9 +204,6 @@ and `x-compress`, is left untouched, matching `fetch()`. As required by
|
||||
[RFC 9659](https://www.rfc-editor.org/rfc/rfc9659.html), a `zstd` frame that
|
||||
requires a window size larger than 8 MB fails to decode.
|
||||
|
||||
> **Experimental:** This interceptor is experimental and subject to change.
|
||||
> A one-time `ExperimentalWarning` is emitted on first use.
|
||||
|
||||
**Parameters**
|
||||
|
||||
* `opts` {Object} (optional)
|
||||
@@ -359,12 +356,25 @@ backing store.
|
||||
|
||||
**Returns:** {Dispatcher.DispatcherComposeInterceptor}
|
||||
|
||||
> **Ordering:** the `cache` interceptor must be composed **after** the
|
||||
> `redirect` interceptor. When `cache` is composed before `redirect`, the cache
|
||||
> handler is wrapped above the redirect handler, so it never observes the
|
||||
> redirect history and its cross-origin / credential-bearing redirect guards are
|
||||
> silently disabled, which lets an attacker-controlled or cross-principal
|
||||
> redirect response be stored under the trusted origin's cache key and replayed
|
||||
> to unrelated callers (GHSA-75VM-9G8F-99J4, GHSA-MQG3-3V4R-CM32,
|
||||
> GHSA-4W7W-5XRC-9H26, GHSA-7XG3-FPHP-28HG). `compose()` throws an
|
||||
> `InvalidArgumentError` for this unsafe order. The `deduplicate` interceptor
|
||||
> participates in the same redirect-history contract and may be placed before or
|
||||
> after `redirect`, as long as `cache` follows `redirect`.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
import { Agent, interceptors, cacheStores } from 'undici'
|
||||
|
||||
const agent = new Agent().compose(
|
||||
interceptors.redirect({ maxRedirections: 5 }),
|
||||
interceptors.cache({ store: new cacheStores.MemoryCacheStore() })
|
||||
)
|
||||
```
|
||||
|
||||
@@ -61,7 +61,7 @@ const success = await bankTransfer('1234567890', '100')
|
||||
|
||||
assert.deepEqual(success, { message: 'transaction processed' })
|
||||
|
||||
// if you dont want to check whether the body or the headers contain the same value
|
||||
// if you don't want to check whether the body or the headers contain the same value
|
||||
// just remove it from interceptor
|
||||
mockPool.intercept({
|
||||
path: '/bank-transfer',
|
||||
|
||||
+55
-5
@@ -2,15 +2,17 @@
|
||||
|
||||
const { addAbortListener } = require('../core/util')
|
||||
const { RequestAbortedError } = require('../core/errors')
|
||||
const { kQueuedAbort } = require('../core/symbols')
|
||||
|
||||
const kListener = Symbol('kListener')
|
||||
const kSignal = Symbol('kSignal')
|
||||
|
||||
function abort (self) {
|
||||
// Keep the reason even when abort is set: a queued request that cannot be
|
||||
// taken out of its queue is aborted once it starts.
|
||||
self.reason = self[kSignal]?.reason ?? new RequestAbortedError()
|
||||
if (self.abort) {
|
||||
self.abort(self[kSignal]?.reason)
|
||||
} else {
|
||||
self.reason = self[kSignal]?.reason ?? new RequestAbortedError()
|
||||
self.abort(self.reason)
|
||||
}
|
||||
removeSignal(self)
|
||||
}
|
||||
@@ -26,7 +28,7 @@ function addSignal (self, signal) {
|
||||
}
|
||||
|
||||
if (signal.aborted) {
|
||||
abort(self)
|
||||
self.reason = signal.reason ?? new RequestAbortedError()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -53,7 +55,55 @@ function removeSignal (self) {
|
||||
self[kListener] = null
|
||||
}
|
||||
|
||||
// Dispatchers call the kQueuedAbort hook while a request waits for a
|
||||
// connection, with a function that takes it out of their queue. Until the
|
||||
// request starts, the handler's abort calls that function.
|
||||
//
|
||||
// A retry or a redirect dispatches the same handler again after an earlier
|
||||
// attempt started. The handler's abort then also calls the controller of that
|
||||
// attempt: it does nothing once the attempt is over, and still reaches a
|
||||
// response that a retry resumes.
|
||||
function queuedAbortHook (handler) {
|
||||
// The abort set by onRequestStart, and the one this hook installed last.
|
||||
let started = null
|
||||
let installed = null
|
||||
return (cancel) => {
|
||||
if (handler.reason) {
|
||||
cancel(handler.reason)
|
||||
return
|
||||
}
|
||||
|
||||
if (handler.abort !== installed) {
|
||||
started = handler.abort
|
||||
}
|
||||
|
||||
if (started === null) {
|
||||
installed = cancel
|
||||
} else {
|
||||
const abortStarted = started
|
||||
installed = (reason) => {
|
||||
abortStarted(reason)
|
||||
cancel(reason)
|
||||
}
|
||||
}
|
||||
handler.abort = installed
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatches a request whose options carry a signal. Requests without a signal
|
||||
// are dispatched directly and never reach this function.
|
||||
function dispatchWithSignal (dispatcher, opts, handler) {
|
||||
if (handler.reason) {
|
||||
// Already aborted: fail without dispatching, so no connection is opened.
|
||||
handler.onResponseError(null, handler.reason)
|
||||
return
|
||||
}
|
||||
|
||||
dispatcher.dispatch({ ...opts, [kQueuedAbort]: queuedAbortHook(handler) }, handler)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addSignal,
|
||||
removeSignal
|
||||
removeSignal,
|
||||
dispatchWithSignal
|
||||
}
|
||||
+6
-2
@@ -4,7 +4,7 @@ const assert = require('node:assert')
|
||||
const { AsyncResource } = require('node:async_hooks')
|
||||
const { InvalidArgumentError, SocketError } = require('../core/errors')
|
||||
const util = require('../core/util')
|
||||
const { addSignal, removeSignal } = require('./abort-signal')
|
||||
const { addSignal, removeSignal, dispatchWithSignal } = require('./abort-signal')
|
||||
|
||||
class ConnectHandler extends AsyncResource {
|
||||
constructor (opts, callback) {
|
||||
@@ -99,7 +99,11 @@ function connect (opts, callback) {
|
||||
try {
|
||||
const connectHandler = new ConnectHandler(opts, callback)
|
||||
const connectOptions = { ...opts, method: 'CONNECT' }
|
||||
this.dispatch(connectOptions, connectHandler)
|
||||
if (opts.signal == null) {
|
||||
this.dispatch(connectOptions, connectHandler)
|
||||
} else {
|
||||
dispatchWithSignal(this, connectOptions, connectHandler)
|
||||
}
|
||||
} catch (err) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw err
|
||||
|
||||
+8
-3
@@ -14,7 +14,7 @@ const {
|
||||
} = require('../core/errors')
|
||||
const util = require('../core/util')
|
||||
const { kBodyUsed } = require('../core/symbols')
|
||||
const { addSignal, removeSignal } = require('./abort-signal')
|
||||
const { addSignal, removeSignal, dispatchWithSignal } = require('./abort-signal')
|
||||
|
||||
function noop () {}
|
||||
|
||||
@@ -126,7 +126,7 @@ class PipelineHandler extends AsyncResource {
|
||||
err = new RequestAbortedError()
|
||||
}
|
||||
|
||||
if (abort && err) {
|
||||
if (abort && (err || !res?.readableEnded)) {
|
||||
abort()
|
||||
}
|
||||
|
||||
@@ -255,7 +255,12 @@ class PipelineHandler extends AsyncResource {
|
||||
function pipeline (opts, handler) {
|
||||
try {
|
||||
const pipelineHandler = new PipelineHandler(opts, handler)
|
||||
this.dispatch({ ...opts, body: pipelineHandler.req }, pipelineHandler)
|
||||
const pipelineOpts = { ...opts, body: pipelineHandler.req }
|
||||
if (opts.signal == null) {
|
||||
this.dispatch(pipelineOpts, pipelineHandler)
|
||||
} else {
|
||||
dispatchWithSignal(this, pipelineOpts, pipelineHandler)
|
||||
}
|
||||
return pipelineHandler.ret
|
||||
} catch (err) {
|
||||
return new PassThrough().destroy(err)
|
||||
|
||||
+13
-5
@@ -5,6 +5,7 @@ const { AsyncResource } = require('node:async_hooks')
|
||||
const { Readable } = require('./readable')
|
||||
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
|
||||
const util = require('../core/util')
|
||||
const { dispatchWithSignal } = require('./abort-signal')
|
||||
|
||||
function noop () {}
|
||||
|
||||
@@ -37,6 +38,11 @@ class RequestHandler extends AsyncResource {
|
||||
throw new InvalidArgumentError('invalid onInfo callback')
|
||||
}
|
||||
|
||||
// Reject before dispatching: onRequestStart only runs once a connection is established.
|
||||
if (signal?.aborted) {
|
||||
throw signal.reason ?? new RequestAbortedError()
|
||||
}
|
||||
|
||||
super('UNDICI_REQUEST')
|
||||
} catch (err) {
|
||||
if (util.isStream(body)) {
|
||||
@@ -60,9 +66,7 @@ class RequestHandler extends AsyncResource {
|
||||
this.reason = null
|
||||
this.removeAbortListener = null
|
||||
|
||||
if (signal?.aborted) {
|
||||
this.reason = signal.reason ?? new RequestAbortedError()
|
||||
} else if (signal) {
|
||||
if (signal) {
|
||||
this.removeAbortListener = util.addAbortListener(signal, () => {
|
||||
this.reason = signal.reason ?? new RequestAbortedError()
|
||||
if (this.res) {
|
||||
@@ -103,7 +107,7 @@ class RequestHandler extends AsyncResource {
|
||||
|
||||
if (statusCode < 200) {
|
||||
if (this.onInfo) {
|
||||
this.onInfo({ statusCode, headers: responseHeaderData })
|
||||
this.runInAsyncScope(this.onInfo, null, { statusCode, headers: responseHeaderData })
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -230,7 +234,11 @@ function request (opts, callback) {
|
||||
try {
|
||||
const handler = new RequestHandler(opts, callback)
|
||||
|
||||
this.dispatch(opts, handler)
|
||||
if (opts.signal == null) {
|
||||
this.dispatch(opts, handler)
|
||||
} else {
|
||||
dispatchWithSignal(this, opts, handler)
|
||||
}
|
||||
} catch (err) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw err
|
||||
|
||||
+6
-2
@@ -4,7 +4,7 @@ const assert = require('node:assert')
|
||||
const { AsyncResource } = require('node:async_hooks')
|
||||
const { InvalidArgumentError, InvalidReturnValueError } = require('../core/errors')
|
||||
const util = require('../core/util')
|
||||
const { addSignal, removeSignal } = require('./abort-signal')
|
||||
const { addSignal, removeSignal, dispatchWithSignal } = require('./abort-signal')
|
||||
|
||||
function noop () {}
|
||||
|
||||
@@ -257,7 +257,11 @@ function stream (opts, factory, callback) {
|
||||
try {
|
||||
const handler = new StreamHandler(opts, factory, callback)
|
||||
|
||||
this.dispatch(opts, handler)
|
||||
if (opts.signal == null) {
|
||||
this.dispatch(opts, handler)
|
||||
} else {
|
||||
dispatchWithSignal(this, opts, handler)
|
||||
}
|
||||
} catch (err) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw err
|
||||
|
||||
+6
-2
@@ -5,7 +5,7 @@ const { AsyncResource } = require('node:async_hooks')
|
||||
const assert = require('node:assert')
|
||||
const util = require('../core/util')
|
||||
const { kHTTP2Stream } = require('../core/symbols')
|
||||
const { addSignal, removeSignal } = require('./abort-signal')
|
||||
const { addSignal, removeSignal, dispatchWithSignal } = require('./abort-signal')
|
||||
|
||||
class UpgradeHandler extends AsyncResource {
|
||||
constructor (opts, callback) {
|
||||
@@ -108,7 +108,11 @@ function upgrade (opts, callback) {
|
||||
method: opts.method || 'GET',
|
||||
upgrade: opts.protocol || 'Websocket'
|
||||
}
|
||||
this.dispatch(upgradeOpts, upgradeHandler)
|
||||
if (opts.signal == null) {
|
||||
this.dispatch(upgradeOpts, upgradeHandler)
|
||||
} else {
|
||||
dispatchWithSignal(this, upgradeOpts, upgradeHandler)
|
||||
}
|
||||
} catch (err) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw err
|
||||
|
||||
Vendored
+17
@@ -47,6 +47,8 @@ const kHandler = Symbol('handler')
|
||||
const kController = Symbol('controller')
|
||||
const kResume = Symbol('resume')
|
||||
|
||||
function noop () {}
|
||||
|
||||
class RequestController {
|
||||
#paused = false
|
||||
#reason = null
|
||||
@@ -463,12 +465,26 @@ class Request {
|
||||
}
|
||||
}
|
||||
|
||||
// Fails a request that was aborted before it reached a connection. The
|
||||
// handler gets an aborted controller, so wrappers such as RetryHandler can
|
||||
// tell a caller abort apart from a retryable connection failure.
|
||||
onQueuedAbort (reason) {
|
||||
this[kController] = createAbortedController(reason)
|
||||
return this.onResponseError(reason)
|
||||
}
|
||||
|
||||
addHeader (key, value) {
|
||||
processHeader(this, key, value)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
function createAbortedController (reason) {
|
||||
const controller = new RequestController(noop)
|
||||
controller.abort(reason)
|
||||
return controller
|
||||
}
|
||||
|
||||
function processHeader (request, key, val) {
|
||||
if (val && (typeof val === 'object' && !Array.isArray(val))) {
|
||||
throw new InvalidArgumentError(`invalid ${key} header`)
|
||||
@@ -580,3 +596,4 @@ function isUndiciFormData (body) {
|
||||
}
|
||||
|
||||
module.exports = Request
|
||||
module.exports.createAbortedController = createAbortedController
|
||||
Vendored
+3
-1
@@ -60,6 +60,7 @@ module.exports = {
|
||||
kMaxResponseSize: Symbol('max response size'),
|
||||
kHTTP2Session: Symbol('http2Session'),
|
||||
kHTTP2Options: Symbol('http2 options'),
|
||||
kQueuedAbort: Symbol('queued abort'),
|
||||
kHTTP2SessionState: Symbol('http2Session state'),
|
||||
kRetryHandlerDefaultRetry: Symbol('retry agent default retry'),
|
||||
kConstruct: Symbol('constructable'),
|
||||
@@ -77,5 +78,6 @@ module.exports = {
|
||||
kNoProxyAgent: Symbol('no proxy agent'),
|
||||
kHttpProxyAgent: Symbol('http proxy agent'),
|
||||
kHttpsProxyAgent: Symbol('https proxy agent'),
|
||||
kSocks5ProxyAgent: Symbol('socks5 proxy agent')
|
||||
kSocks5ProxyAgent: Symbol('socks5 proxy agent'),
|
||||
kInterceptorKind: Symbol('interceptor kind')
|
||||
}
|
||||
+11
-2
@@ -96,7 +96,7 @@ class Agent extends DispatcherBase {
|
||||
? { ...this[kOptions], allowH2: false }
|
||||
: this[kOptions])
|
||||
|
||||
const closeClientIfUnused = () => {
|
||||
const closeClientIfUnused = (deferred = false) => {
|
||||
if (this[kClients].get(key) !== dispatcher) {
|
||||
return
|
||||
}
|
||||
@@ -106,7 +106,16 @@ class Agent extends DispatcherBase {
|
||||
// no connected clients and is not busy, but it still has pending work.
|
||||
// Closing it here lets the replacement Client finish those requests
|
||||
// and then destroys that new connection with ClientDestroyedError.
|
||||
if (dispatcher[kConnected] > 0 || dispatcher[kBusy] || dispatcher[kPending] > 0) {
|
||||
if (dispatcher[kConnected] > 0 || dispatcher[kBusy]) {
|
||||
return
|
||||
}
|
||||
|
||||
if (dispatcher[kPending] > 0) {
|
||||
if (!deferred) {
|
||||
queueMicrotask(() => {
|
||||
closeClientIfUnused(true)
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+24
@@ -67,6 +67,7 @@ const removeAllListeners = util.removeAllListeners
|
||||
const kIdleSocketValidation = Symbol('kIdleSocketValidation')
|
||||
const kIdleSocketValidationTimeout = Symbol('kIdleSocketValidationTimeout')
|
||||
const kSocketUsed = Symbol('kSocketUsed')
|
||||
const kIdleSince = Symbol('kIdleSince')
|
||||
const kTypeOfService = Symbol('kTypeOfService')
|
||||
|
||||
let extractBody
|
||||
@@ -1107,6 +1108,19 @@ function scheduleIdleSocketValidation (client, socket) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* kIdleSince is recorded when the keep-alive timer is armed, so this never
|
||||
* expires a socket before that timer is due.
|
||||
* @param {import('net').Socket} socket
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isIdleSocketExpired (socket) {
|
||||
const parser = socket[kParser]
|
||||
return parser.timeoutType === TIMEOUT_KEEP_ALIVE &&
|
||||
parser.timeoutValue > 0 &&
|
||||
performance.now() - socket[kIdleSince] >= parser.timeoutValue
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./client.js')} client
|
||||
*/
|
||||
@@ -1124,6 +1138,15 @@ function resumeH1 (client) {
|
||||
socket[kNoRef] = false
|
||||
}
|
||||
|
||||
// The keep-alive timer cannot fire while the event loop is blocked, and a
|
||||
// request dispatched from the poll phase passes the idle socket validation
|
||||
// below before that timer or a FIN received during the block is processed.
|
||||
// Check the clock so that an expired socket is not reused.
|
||||
if (client[kRunning] === 0 && client[kPending] > 0 && isIdleSocketExpired(socket)) {
|
||||
util.destroy(socket, new InformationalError('socket idle timeout'))
|
||||
return
|
||||
}
|
||||
|
||||
if (client[kRunning] === 0 && client[kPending] > 0 && socket[kSocketUsed]) {
|
||||
if (socket[kIdleSocketValidation] === 0) {
|
||||
scheduleIdleSocketValidation(client, socket)
|
||||
@@ -1152,6 +1175,7 @@ function resumeH1 (client) {
|
||||
|
||||
if (client[kSize] === 0) {
|
||||
if (socket[kParser].timeoutType !== TIMEOUT_KEEP_ALIVE) {
|
||||
socket[kIdleSince] = performance.now()
|
||||
socket[kParser].setTimeout(client[kKeepAliveTimeoutValue], TIMEOUT_KEEP_ALIVE)
|
||||
}
|
||||
} else if (client[kRunning] > 0 && socket[kParser].statusCode < 200) {
|
||||
|
||||
+31
-8
@@ -91,6 +91,7 @@ const {
|
||||
HTTP2_HEADER_STATUS,
|
||||
HTTP2_HEADER_PROTOCOL,
|
||||
NGHTTP2_NO_ERROR,
|
||||
NGHTTP2_PROTOCOL_ERROR,
|
||||
NGHTTP2_REFUSED_STREAM
|
||||
}
|
||||
} = http2
|
||||
@@ -300,7 +301,9 @@ function connectH2 (client, socket) {
|
||||
// refH2Session/unrefH2Session.
|
||||
refed: true,
|
||||
ping: {
|
||||
interval: client[kHTTP2Options].pingInterval === 0 ? null : setInterval(onHttp2SendPing, client[kHTTP2Options].pingInterval, session).unref()
|
||||
interval: client[kHTTP2Options].pingInterval === 0 ? null : setInterval(onHttp2SendPing, client[kHTTP2Options].pingInterval, session).unref(),
|
||||
// Set while a periodic PING waits for its ack.
|
||||
pending: false
|
||||
}
|
||||
}
|
||||
session[kReceivedGoAway] = false
|
||||
@@ -565,6 +568,10 @@ function onHttp2ProbeTimeout (session) {
|
||||
return
|
||||
}
|
||||
|
||||
resetUnresponsiveHttp2Session(session)
|
||||
}
|
||||
|
||||
function resetUnresponsiveHttp2Session (session) {
|
||||
const err = new SocketError('HTTP/2: connection unresponsive', util.getSocketInfo(session[kSocket]))
|
||||
session[kError] = err
|
||||
resetHttp2Session(session, err)
|
||||
@@ -658,16 +665,27 @@ function onHttp2SendPing (session) {
|
||||
return
|
||||
}
|
||||
|
||||
// If no ping sent, do nothing
|
||||
// An unacked PING never calls back, so a connection that silently died
|
||||
// (dropped by a NAT or load balancer, a hung peer) would be kept forever when
|
||||
// no stream times out on it, e.g. when every request is aborted first.
|
||||
if (state.ping.pending) {
|
||||
resetUnresponsiveHttp2Session(session)
|
||||
return
|
||||
}
|
||||
|
||||
state.ping.pending = true
|
||||
session.ping(onPing.bind(session))
|
||||
|
||||
function onPing (err, duration) {
|
||||
state.ping.pending = false
|
||||
|
||||
const client = this[kClient]
|
||||
const socket = this[kSocket]
|
||||
|
||||
if (err != null) {
|
||||
const error = new InformationalError(`HTTP/2: "PING" errored - type ${err.message}`)
|
||||
socket[kError] = error
|
||||
// Keep the reason the session was torn down if that is what cancelled the PING.
|
||||
socket[kError] ??= error
|
||||
client[kOnError](error)
|
||||
} else {
|
||||
client.emit('ping', duration)
|
||||
@@ -1684,11 +1702,16 @@ function onError (err) {
|
||||
// noop error sink so that re-delivery cannot go unhandled.
|
||||
stream.on('error', noop)
|
||||
|
||||
// Node's HTTP/2 implementation can turn an incomplete Content-Length body
|
||||
// into a protocol stream error instead of emitting 'end'. Prefer the
|
||||
// content-length mismatch error when the received byte count proves it.
|
||||
if (state.responseContentLength != null && state.bytesRead !== state.responseContentLength) {
|
||||
err = new ResponseContentLengthMismatchError()
|
||||
// Node may report Content-Length violations as protocol errors.
|
||||
if (
|
||||
(err.code === 'ERR_HTTP2_ERROR' ||
|
||||
(err.code === 'ERR_HTTP2_STREAM_ERROR' && stream.rstCode === NGHTTP2_PROTOCOL_ERROR)) &&
|
||||
state.responseContentLength != null &&
|
||||
state.bytesRead !== state.responseContentLength
|
||||
) {
|
||||
const mismatch = new ResponseContentLengthMismatchError()
|
||||
mismatch.cause = err
|
||||
err = mismatch
|
||||
}
|
||||
|
||||
if (typeof stream.rstCode === 'number' && stream.rstCode !== NGHTTP2_NO_ERROR) {
|
||||
|
||||
+140
-11
@@ -55,12 +55,14 @@ const {
|
||||
kHostAuthority,
|
||||
kResume,
|
||||
kHTTP2Options,
|
||||
kUseMilo
|
||||
kUseMilo,
|
||||
kQueuedAbort
|
||||
} = require('../core/symbols.js')
|
||||
const connectH1 = require('./client-h1.js')
|
||||
const connectH2 = require('./client-h2.js')
|
||||
|
||||
const kClosedResolve = Symbol('kClosedResolve')
|
||||
const kCancelConnect = Symbol('kCancelConnect')
|
||||
|
||||
const getDefaultNodeMaxHeaderSize = http &&
|
||||
http.maxHeaderSize &&
|
||||
@@ -322,6 +324,7 @@ class Client extends DispatcherBase {
|
||||
this[kClosedResolve] = null
|
||||
this[kMaxResponseSize] = maxResponseSize > -1 ? maxResponseSize : -1
|
||||
this[kHTTPContext] = null
|
||||
this[kCancelConnect] = null
|
||||
// h2
|
||||
this[kHTTP2Options] = {
|
||||
pingInterval: h2Options?.pingInterval ?? pingInterval ?? 60e3,
|
||||
@@ -402,6 +405,8 @@ class Client extends DispatcherBase {
|
||||
|
||||
[kConnect] (cb) {
|
||||
connect(this)
|
||||
// Asked for explicitly: keep it even if no request waits for it.
|
||||
this[kCancelConnect] = null
|
||||
this.once('connect', cb)
|
||||
}
|
||||
|
||||
@@ -419,6 +424,15 @@ class Client extends DispatcherBase {
|
||||
this[kResume](true)
|
||||
}
|
||||
|
||||
if (request.abort === null && !request.aborted) {
|
||||
// The request is still waiting for a connection: if its handler listens
|
||||
// to a signal, give it a way to take the request out of the queue.
|
||||
const onQueued = opts[kQueuedAbort]
|
||||
if (onQueued !== undefined) {
|
||||
onQueued((reason) => abortPendingRequest(this, request, reason))
|
||||
}
|
||||
}
|
||||
|
||||
if (this[kResuming] && this[kNeedDrain] !== 2 && this[kBusy]) {
|
||||
this[kNeedDrain] = 2
|
||||
}
|
||||
@@ -469,6 +483,56 @@ class Client extends DispatcherBase {
|
||||
}
|
||||
}
|
||||
|
||||
function failQueuedRequest (client, request, reason) {
|
||||
try {
|
||||
request.onQueuedAbort(reason)
|
||||
assert(request.aborted)
|
||||
} catch (err) {
|
||||
client.emit('error', err)
|
||||
}
|
||||
}
|
||||
|
||||
function abortPendingRequest (client, request, reason) {
|
||||
// The request already settled, or it started and its handler owns the abort.
|
||||
if (request.aborted || request.abort !== null) {
|
||||
return
|
||||
}
|
||||
|
||||
const queue = client[kQueue]
|
||||
const idx = queue.indexOf(request, client[kPendingIdx])
|
||||
if (idx === -1) {
|
||||
return
|
||||
}
|
||||
|
||||
// _resume() may be handing this request to the connection right now, before
|
||||
// onRequestStart runs. Leave it there: the handler aborts it once it starts.
|
||||
if (idx === client[kPendingIdx] && client[kResuming] === 2) {
|
||||
return
|
||||
}
|
||||
|
||||
queue.splice(idx, 1)
|
||||
failQueuedRequest(client, request, reason)
|
||||
|
||||
// The client may no longer be busy: emit 'drain' so a Pool can use it again.
|
||||
client[kResume](true)
|
||||
|
||||
if (client[kCancelConnect] !== null && client[kSize] === 0) {
|
||||
// The drain is emitted in a microtask: check once a Pool had the chance to
|
||||
// hand this client the requests it queued.
|
||||
queueMicrotask(() => cancelUnusedConnect(client))
|
||||
}
|
||||
}
|
||||
|
||||
// A connection attempt that no request waits for only holds a connection slot,
|
||||
// until it connects or times out. Destroy it, so the next request starts a new
|
||||
// one instead of waiting for it.
|
||||
function cancelUnusedConnect (client) {
|
||||
const cancel = client[kCancelConnect]
|
||||
if (cancel !== null && client[kSize] === 0) {
|
||||
cancel(new InformationalError('no request waits for this connection'))
|
||||
}
|
||||
}
|
||||
|
||||
function onError (client, err) {
|
||||
if (
|
||||
client[kRunning] === 0 &&
|
||||
@@ -515,6 +579,38 @@ function connect (client) {
|
||||
|
||||
client[kConnecting] = true
|
||||
|
||||
// The name this attempt verifies the server's certificate for. While it
|
||||
// connects, its requests can be aborted and _resume() can switch
|
||||
// client[kServerName] to the name of the next queued request.
|
||||
const servername = client[kServerName]
|
||||
|
||||
let calledBack = false
|
||||
let cancelled = false
|
||||
|
||||
// Ends this attempt without a 'connectionError': no request failed, and a
|
||||
// Pool would retire this client.
|
||||
const abandon = (socket, err) => {
|
||||
client[kConnecting] = false
|
||||
|
||||
if (channels.connectError.hasSubscribers) {
|
||||
channels.connectError.publish({
|
||||
connectParams: {
|
||||
host,
|
||||
hostname,
|
||||
protocol,
|
||||
port,
|
||||
version: client[kHTTPContext]?.version,
|
||||
servername,
|
||||
localAddress: client[kLocalAddress]
|
||||
},
|
||||
connector: client[kConnector],
|
||||
error: err
|
||||
})
|
||||
}
|
||||
|
||||
util.destroy(socket.on('error', noop), err)
|
||||
}
|
||||
|
||||
if (channels.beforeConnect.hasSubscribers) {
|
||||
channels.beforeConnect.publish({
|
||||
connectParams: {
|
||||
@@ -523,7 +619,7 @@ function connect (client) {
|
||||
protocol,
|
||||
port,
|
||||
version: client[kHTTPContext]?.version,
|
||||
servername: client[kServerName],
|
||||
servername,
|
||||
localAddress: client[kLocalAddress]
|
||||
},
|
||||
connector: client[kConnector]
|
||||
@@ -531,16 +627,27 @@ function connect (client) {
|
||||
}
|
||||
|
||||
try {
|
||||
client[kConnector]({
|
||||
const connecting = client[kConnector]({
|
||||
host,
|
||||
hostname,
|
||||
protocol,
|
||||
port,
|
||||
servername: client[kServerName],
|
||||
servername,
|
||||
localAddress: client[kLocalAddress]
|
||||
}, (err, socket) => {
|
||||
calledBack = true
|
||||
|
||||
if (cancelled) {
|
||||
if (socket) {
|
||||
util.destroy(socket.on('error', noop))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
client[kCancelConnect] = null
|
||||
|
||||
if (err) {
|
||||
handleConnectError(client, err, { host, hostname, protocol, port })
|
||||
handleConnectError(client, err, { host, hostname, protocol, port, servername })
|
||||
client[kResume]()
|
||||
return
|
||||
}
|
||||
@@ -553,13 +660,21 @@ function connect (client) {
|
||||
|
||||
assert(socket)
|
||||
|
||||
if (client[kServerName] !== servername) {
|
||||
// The server proved its identity for another name than the one the
|
||||
// queued requests are for: never send them on this connection.
|
||||
abandon(socket, new InformationalError('servername changed'))
|
||||
client[kResume]()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
client[kHTTPContext] = socket.alpnProtocol === 'h2'
|
||||
? connectH2(client, socket)
|
||||
: connectH1(client, socket)
|
||||
} catch (err) {
|
||||
socket.destroy().on('error', noop)
|
||||
handleConnectError(client, err, { host, hostname, protocol, port })
|
||||
handleConnectError(client, err, { host, hostname, protocol, port, servername })
|
||||
client[kResume]()
|
||||
return
|
||||
}
|
||||
@@ -579,7 +694,7 @@ function connect (client) {
|
||||
protocol,
|
||||
port,
|
||||
version: client[kHTTPContext]?.version,
|
||||
servername: client[kServerName],
|
||||
servername,
|
||||
localAddress: client[kLocalAddress]
|
||||
},
|
||||
connector: client[kConnector],
|
||||
@@ -590,13 +705,23 @@ function connect (client) {
|
||||
client.emit('connect', client[kUrl], [client])
|
||||
client[kResume]()
|
||||
})
|
||||
|
||||
// The attempt can only be cancelled through the socket the connector
|
||||
// returns. The built-in connector returns it; custom connectors may not.
|
||||
if (!calledBack && util.isStream(connecting)) {
|
||||
client[kCancelConnect] = (err) => {
|
||||
cancelled = true
|
||||
client[kCancelConnect] = null
|
||||
abandon(connecting, err)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
handleConnectError(client, err, { host, hostname, protocol, port })
|
||||
handleConnectError(client, err, { host, hostname, protocol, port, servername })
|
||||
client[kResume]()
|
||||
}
|
||||
}
|
||||
|
||||
function handleConnectError (client, err, { host, hostname, protocol, port }) {
|
||||
function handleConnectError (client, err, { host, hostname, protocol, port, servername }) {
|
||||
if (client.destroyed) {
|
||||
return
|
||||
}
|
||||
@@ -611,7 +736,7 @@ function handleConnectError (client, err, { host, hostname, protocol, port }) {
|
||||
protocol,
|
||||
port,
|
||||
version: client[kHTTPContext]?.version,
|
||||
servername: client[kServerName],
|
||||
servername,
|
||||
localAddress: client[kLocalAddress]
|
||||
},
|
||||
connector: client[kConnector],
|
||||
@@ -627,7 +752,8 @@ function handleConnectError (client, err, { host, hostname, protocol, port }) {
|
||||
util.errorRequest(client, running[i], err)
|
||||
}
|
||||
|
||||
while (client[kPending] > 0 && client[kQueue][client[kPendingIdx]].servername === client[kServerName]) {
|
||||
// Only the requests for the name the certificate failed for.
|
||||
while (client[kPending] > 0 && client[kQueue][client[kPendingIdx]].servername === servername) {
|
||||
const request = client[kQueue].splice(client[kPendingIdx], 1)[0]
|
||||
util.errorRequest(client, request, err)
|
||||
}
|
||||
@@ -718,6 +844,9 @@ function _resume (client, sync) {
|
||||
client[kHTTPContext] = null
|
||||
resume(client)
|
||||
})
|
||||
// A pending attempt verifies the server for the previous name, and its
|
||||
// connection is discarded once it connects: do not wait for it.
|
||||
client[kCancelConnect]?.(new InformationalError('servername changed'))
|
||||
}
|
||||
|
||||
if (client[kConnecting]) {
|
||||
|
||||
+6
-1
@@ -190,7 +190,12 @@ class DispatcherBase extends Dispatcher {
|
||||
|
||||
handler.onResponseError(null, err)
|
||||
|
||||
return false
|
||||
// The request failed synchronously: no work was queued on this
|
||||
// dispatcher, no capacity was consumed and no 'drain' event will
|
||||
// ever follow. Returning false would make callers (e.g. Pool)
|
||||
// mark this dispatcher as busy waiting for a drain that never
|
||||
// comes, permanently taking it out of rotation.
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,6 +1,7 @@
|
||||
'use strict'
|
||||
const EventEmitter = require('node:events')
|
||||
const { kOriginless, kUrl } = require('../core/symbols')
|
||||
const { InvalidArgumentError } = require('../core/errors')
|
||||
const { kOriginless, kUrl, kInterceptorKind } = require('../core/symbols')
|
||||
|
||||
class Dispatcher extends EventEmitter {
|
||||
dispatch () {
|
||||
@@ -24,6 +25,8 @@ class Dispatcher extends EventEmitter {
|
||||
: this[kUrl]?.origin
|
||||
let dispatch = this.dispatch.bind(this)
|
||||
|
||||
const orderSensitiveKinds = []
|
||||
|
||||
for (const interceptor of interceptors) {
|
||||
if (interceptor == null) {
|
||||
continue
|
||||
@@ -33,6 +36,10 @@ class Dispatcher extends EventEmitter {
|
||||
throw new TypeError(`invalid interceptor, expected function received ${typeof interceptor}`)
|
||||
}
|
||||
|
||||
if (interceptor[kInterceptorKind] != null) {
|
||||
orderSensitiveKinds.push(interceptor[kInterceptorKind])
|
||||
}
|
||||
|
||||
dispatch = interceptor(dispatch, interceptorOrigin)
|
||||
|
||||
if (dispatch == null || typeof dispatch !== 'function' || dispatch.length !== 2) {
|
||||
@@ -40,6 +47,20 @@ class Dispatcher extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
// Several shipped interceptors are order-sensitive: they cooperate through
|
||||
// the redirect history threaded on the request context, and the cache
|
||||
// handler only receives it when the redirect interceptor is composed before
|
||||
// the cache interceptor. Composing `cache` before `redirect` silently
|
||||
// disables the cache's redirect-origin guards (cross-origin cache
|
||||
// poisoning, credential-bearing redirect replay), so fail fast instead of
|
||||
// storing an attacker-controlled or cross-principal response under a key
|
||||
// the application trusts.
|
||||
const cacheIndex = orderSensitiveKinds.indexOf('cache')
|
||||
const redirectIndex = orderSensitiveKinds.indexOf('redirect')
|
||||
if (cacheIndex !== -1 && redirectIndex !== -1 && cacheIndex < redirectIndex) {
|
||||
throw new InvalidArgumentError('the cache interceptor must be composed after the redirect interceptor; composing the cache before the redirect disables the cache\'s cross-origin and credential redirect guards (GHSA-75VM-9G8F-99J4, GHSA-MQG3-3V4R-CM32, GHSA-4W7W-5XRC-9H26, GHSA-7XG3-FPHP-28HG)')
|
||||
}
|
||||
|
||||
const originalDispatch = dispatch
|
||||
const self = this
|
||||
dispatch = function (opts, handler) {
|
||||
|
||||
+72
-16
@@ -4,7 +4,8 @@ const { AsyncResource } = require('node:async_hooks')
|
||||
const { PoolStats } = require('../util/stats.js')
|
||||
const DispatcherBase = require('./dispatcher-base')
|
||||
const FixedQueue = require('./fixed-queue')
|
||||
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
|
||||
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch, kQueuedAbort } = require('../core/symbols')
|
||||
const { createAbortedController } = require('../core/request')
|
||||
|
||||
const kClients = Symbol('clients')
|
||||
const kNeedDrain = Symbol('needDrain')
|
||||
@@ -23,6 +24,8 @@ const kAddClient = Symbol('add client')
|
||||
const kRemoveClient = Symbol('remove client')
|
||||
const kRetireClient = Symbol('retire client')
|
||||
const kRetiring = Symbol('retiring clients')
|
||||
const kShiftQueue = Symbol('shift queue')
|
||||
const kAbortQueued = Symbol('abort queued')
|
||||
|
||||
// Closes every live client, including clients that have been
|
||||
// taken out of rotation but are still finishing their own
|
||||
@@ -36,6 +39,8 @@ class QueuedRequest extends AsyncResource {
|
||||
super('UNDICI_POOL_QUEUED_REQUEST')
|
||||
this.opts = opts
|
||||
this.handler = handler
|
||||
// Cleared once the request leaves the queue, so a late abort is ignored.
|
||||
this.queued = true
|
||||
}
|
||||
|
||||
dispatch (dispatcher) {
|
||||
@@ -75,17 +80,15 @@ class PoolBase extends DispatcherBase {
|
||||
return
|
||||
}
|
||||
|
||||
const queue = this[kQueue]
|
||||
let needDrain = false
|
||||
|
||||
this[kOnClientDrain](client)
|
||||
|
||||
while (!needDrain) {
|
||||
const item = queue.shift()
|
||||
const item = this[kShiftQueue]()
|
||||
if (!item) {
|
||||
break
|
||||
}
|
||||
this[kQueued]--
|
||||
needDrain = !item.dispatch(client)
|
||||
}
|
||||
|
||||
@@ -98,7 +101,7 @@ class PoolBase extends DispatcherBase {
|
||||
// negotiated and hit maxConcurrentStreams. Hand the rest to other
|
||||
// clients, creating new ones up to the connection limit, instead of
|
||||
// leaving them for this client to drain one batch at a time.
|
||||
if (!queue.isEmpty()) {
|
||||
if (this[kQueued] > 0) {
|
||||
return this[kDrainQueue](origin, targets)
|
||||
}
|
||||
}
|
||||
@@ -108,7 +111,7 @@ class PoolBase extends DispatcherBase {
|
||||
this.emit('drain', origin, [this, ...targets])
|
||||
}
|
||||
|
||||
if (this[kClosedResolve] && queue.isEmpty()) {
|
||||
if (this[kClosedResolve] && this[kQueued] === 0) {
|
||||
return closeClients(this).then(this[kClosedResolve])
|
||||
}
|
||||
}
|
||||
@@ -118,23 +121,31 @@ class PoolBase extends DispatcherBase {
|
||||
[kOnClientDrain] () {}
|
||||
|
||||
[kDrainQueue] (origin, targets) {
|
||||
const queue = this[kQueue]
|
||||
let hasDispatcher = true
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
const dispatcher = this[kGetDispatcher]()
|
||||
while (this[kQueued] > 0) {
|
||||
let dispatcher
|
||||
try {
|
||||
dispatcher = this[kGetDispatcher]()
|
||||
} catch (err) {
|
||||
// Selection failed before a dispatcher took ownership of this item.
|
||||
const item = this[kShiftQueue]()
|
||||
item.runInAsyncScope(item.handler.onResponseError, item.handler, null, err)
|
||||
// The error handler may synchronously dispatch and consume capacity.
|
||||
hasDispatcher = !this.destroyed && this[kHasDispatcher](false)
|
||||
continue
|
||||
}
|
||||
if (!dispatcher) {
|
||||
hasDispatcher = false
|
||||
break
|
||||
}
|
||||
|
||||
const item = queue.shift()
|
||||
this[kQueued]--
|
||||
const item = this[kShiftQueue]()
|
||||
|
||||
if (!item.dispatch(dispatcher)) {
|
||||
dispatcher[kNeedDrain] = true
|
||||
this[kOnClientBusy](dispatcher)
|
||||
hasDispatcher = this[kHasDispatcher]()
|
||||
hasDispatcher = this[kHasDispatcher](false)
|
||||
if (!hasDispatcher) {
|
||||
break
|
||||
}
|
||||
@@ -146,11 +157,48 @@ class PoolBase extends DispatcherBase {
|
||||
this.emit('drain', origin, [this, ...targets])
|
||||
}
|
||||
|
||||
if (this[kClosedResolve] && queue.isEmpty()) {
|
||||
if (this[kClosedResolve] && this[kQueued] === 0) {
|
||||
return closeClients(this).then(this[kClosedResolve])
|
||||
}
|
||||
}
|
||||
|
||||
// Aborted requests stay in the queue as tombstones (queued === false) and
|
||||
// are skipped here; kQueued only counts the live ones.
|
||||
[kShiftQueue] () {
|
||||
const queue = this[kQueue]
|
||||
let item = queue.shift()
|
||||
while (item !== null && item.queued === false) {
|
||||
item = queue.shift()
|
||||
}
|
||||
|
||||
if (item !== null) {
|
||||
this[kQueued]--
|
||||
item.queued = false
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
// Called through the handler's kQueuedAbort hook when a queued request is
|
||||
// aborted.
|
||||
[kAbortQueued] (item, reason) {
|
||||
if (!item.queued) {
|
||||
return
|
||||
}
|
||||
|
||||
const { handler } = item
|
||||
item.queued = false
|
||||
item.opts = null
|
||||
item.handler = null
|
||||
this[kQueued]--
|
||||
|
||||
item.runInAsyncScope(handler.onResponseError, handler, createAbortedController(reason), reason)
|
||||
|
||||
if (this[kClosedResolve] && this[kQueued] === 0) {
|
||||
closeClients(this).then(this[kClosedResolve])
|
||||
}
|
||||
}
|
||||
|
||||
[kOnConnect] = (origin, targets) => {
|
||||
this.emit('connect', origin, [this, ...targets])
|
||||
};
|
||||
@@ -212,7 +260,7 @@ class PoolBase extends DispatcherBase {
|
||||
}
|
||||
|
||||
[kClose] () {
|
||||
if (this[kQueue].isEmpty()) {
|
||||
if (this[kQueued] === 0) {
|
||||
return closeClients(this)
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
@@ -223,7 +271,7 @@ class PoolBase extends DispatcherBase {
|
||||
|
||||
[kDestroy] (err) {
|
||||
while (true) {
|
||||
const item = this[kQueue].shift()
|
||||
const item = this[kShiftQueue]()
|
||||
if (!item) {
|
||||
break
|
||||
}
|
||||
@@ -244,9 +292,17 @@ class PoolBase extends DispatcherBase {
|
||||
const dispatcher = this[kGetDispatcher]()
|
||||
|
||||
if (!dispatcher) {
|
||||
const item = new QueuedRequest(opts, handler)
|
||||
this[kNeedDrain] = true
|
||||
this[kQueue].push(new QueuedRequest(opts, handler))
|
||||
this[kQueue].push(item)
|
||||
this[kQueued]++
|
||||
|
||||
const onQueued = opts[kQueuedAbort]
|
||||
if (onQueued !== undefined) {
|
||||
// Give the handler a way to remove the request from the queue as soon
|
||||
// as it is aborted.
|
||||
onQueued((reason) => this[kAbortQueued](item, reason))
|
||||
}
|
||||
} else if (!dispatcher.dispatch(opts, handler)) {
|
||||
dispatcher[kNeedDrain] = true
|
||||
this[kOnClientBusy](dispatcher)
|
||||
|
||||
+22
-9
@@ -18,7 +18,7 @@ const {
|
||||
InvalidArgumentError
|
||||
} = require('../core/errors')
|
||||
const util = require('../core/util')
|
||||
const { kConnecting, kHTTPContext, kUrl, kQueued } = require('../core/symbols')
|
||||
const { kConnecting, kHTTPContext, kHTTP2Session, kRemoteSettings, kUrl, kQueued } = require('../core/symbols')
|
||||
const buildConnector = require('../core/connect')
|
||||
|
||||
const kOptions = Symbol('options')
|
||||
@@ -116,12 +116,25 @@ class Pool extends PoolBase {
|
||||
}
|
||||
|
||||
if (client === this[kProtocolProbe]) {
|
||||
// An h2 Client's drain event releases the requests accumulated during
|
||||
// negotiation onto that Client. If ALPN selected h1, release the probe
|
||||
// immediately and restore normal Pool fan-out instead.
|
||||
if (this[kProtocol] !== 'h2') {
|
||||
this[kProtocolProbe] = null
|
||||
this[kDrainQueue](origin, targets.slice(1))
|
||||
const releaseProbe = () => {
|
||||
if (client === this[kProtocolProbe]) {
|
||||
this[kProtocolProbe] = null
|
||||
// An empty queue must not release backpressure when this client
|
||||
// is still saturated and the connection limit prevents fan-out.
|
||||
// Check capacity without invoking a factory for unused capacity.
|
||||
if (!this.destroyed && (this[kQueued] > 0 || (!this.closed && this[kHasDispatcher](false)))) {
|
||||
this[kDrainQueue](origin, targets.slice(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
const session = client[kHTTP2Session]
|
||||
// A peer's stream limit can keep the probe busy indefinitely. Once
|
||||
// SETTINGS arrive, queued work may need another connection without
|
||||
// waiting for this client's drain event.
|
||||
if (this[kProtocol] !== 'h2' || session[kRemoteSettings]) {
|
||||
releaseProbe()
|
||||
} else {
|
||||
session.once('remoteSettings', releaseProbe)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -200,7 +213,7 @@ class Pool extends PoolBase {
|
||||
}
|
||||
}
|
||||
|
||||
[kHasDispatcher] () {
|
||||
[kHasDispatcher] (create = true) {
|
||||
const clientTtlOption = this[kOptions].clientTtl
|
||||
for (let i = 0; i < this[kClients].length; i++) {
|
||||
const client = this[kClients][i]
|
||||
@@ -218,7 +231,7 @@ class Pool extends PoolBase {
|
||||
}
|
||||
|
||||
if (!this[kConnections] || this[kClients].length < this[kConnections]) {
|
||||
createClient(this)
|
||||
if (create) createClient(this)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -159,8 +159,10 @@ class ProxyAgent extends DispatcherBase {
|
||||
headers: this[kProxyHeaders],
|
||||
connect,
|
||||
factory: agentFactory,
|
||||
username: opts.username || username,
|
||||
password: opts.password || password,
|
||||
// Socks5ProxyAgent decodes the credentials embedded in the URI;
|
||||
// the URL getters return them still percent-encoded.
|
||||
username: opts.username,
|
||||
password: opts.password,
|
||||
connectTimeout,
|
||||
proxyTls: opts.proxyTls,
|
||||
requestTls: opts.requestTls
|
||||
|
||||
+1
-1
@@ -412,7 +412,7 @@ class CacheHandler {
|
||||
deleteCachedValue(this.#store, this.#cacheKey)
|
||||
}
|
||||
|
||||
// Don't have anything to tell us this response is cachable and we're not
|
||||
// Don't have anything to tell us this response is cacheable and we're not
|
||||
// caching by default
|
||||
return downstreamOnHeaders()
|
||||
}
|
||||
|
||||
+27
-1
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
const assert = require('node:assert')
|
||||
|
||||
const { kRetryHandlerDefaultRetry } = require('../core/symbols')
|
||||
const { kRetryHandlerDefaultRetry, kQueuedAbort } = require('../core/symbols')
|
||||
const { RequestRetryError, RequestAbortedError } = require('../core/errors')
|
||||
const {
|
||||
hasSafeIterator,
|
||||
@@ -98,6 +98,11 @@ class RetryController {
|
||||
}
|
||||
|
||||
class RetryHandler {
|
||||
// Takes the retry that waits for a connection out of its queue.
|
||||
#queuedCancel = null
|
||||
// Whether retries are dispatched with a hook that sets #queuedCancel.
|
||||
#tracksQueuedRetry = false
|
||||
|
||||
constructor (opts, { dispatch, handler }) {
|
||||
const { retryOptions, ...dispatchOpts } = opts
|
||||
const {
|
||||
@@ -561,6 +566,18 @@ class RetryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.#tracksQueuedRetry) {
|
||||
// The consumer's controller still targets the earlier attempt, so an
|
||||
// abort would not reach a retry that waits for a connection. Keep the
|
||||
// function that takes it out of its queue; the caller's hook still runs.
|
||||
this.#tracksQueuedRetry = true
|
||||
const onQueued = this.opts[kQueuedAbort]
|
||||
this.opts[kQueuedAbort] = (cancel) => {
|
||||
this.#queuedCancel = cancel
|
||||
onQueued?.(cancel)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.retryCountCheckpoint = this.retryCount
|
||||
this.dispatch(this.opts, this)
|
||||
@@ -622,6 +639,15 @@ class RetryHandler {
|
||||
}
|
||||
|
||||
#onAbort (reason) {
|
||||
// A retry that waits for a connection is taken out of its queue: its
|
||||
// dispatcher fails it with an aborted controller, so onResponseError passes
|
||||
// the abort on instead of retrying. Once the retry started, this does nothing.
|
||||
const cancel = this.#queuedCancel
|
||||
if (cancel !== null) {
|
||||
this.#queuedCancel = null
|
||||
cancel(reason ?? new RequestAbortedError())
|
||||
}
|
||||
|
||||
// A consumer abort lands on the controller proxy. If the retry policy is
|
||||
// still deciding (typically holding a backoff timer), cancel the wait and
|
||||
// surface the abort immediately instead of letting the request hang until
|
||||
|
||||
+9
-2
@@ -18,7 +18,9 @@ const {
|
||||
isEtagUsable
|
||||
} = require('../util/cache.js')
|
||||
const { AbortError } = require('../core/errors.js')
|
||||
const { kQueuedAbort } = require('../core/symbols.js')
|
||||
const { parseHttpDate } = require('../util/date.js')
|
||||
const { kInterceptorKind } = require('../core/symbols.js')
|
||||
|
||||
/**
|
||||
* @param {(string | RegExp)[] | undefined} origins
|
||||
@@ -541,7 +543,10 @@ function handleResult (
|
||||
dispatch(
|
||||
{
|
||||
...opts,
|
||||
headers
|
||||
headers,
|
||||
// The revalidation is not the caller's request: aborting the
|
||||
// caller must not cancel it while it waits for a connection.
|
||||
[kQueuedAbort]: undefined
|
||||
},
|
||||
new CacheHandler(globalOpts, cacheKey, {
|
||||
// Silent handler that just updates the cache
|
||||
@@ -665,7 +670,7 @@ module.exports = (opts = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
return (dispatch, interceptorOrigin) => {
|
||||
const interceptor = (dispatch, interceptorOrigin) => {
|
||||
return (opts, handler) => {
|
||||
const requestOrigin = getInterceptorOrigin(opts, interceptorOrigin)
|
||||
if (!requestOrigin || arrayIncludes(safeMethodsToNotCache, opts.method)) {
|
||||
@@ -768,4 +773,6 @@ module.exports = (opts = {}) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
interceptor[kInterceptorKind] = 'cache'
|
||||
return interceptor
|
||||
}
|
||||
-11
@@ -105,8 +105,6 @@ function createMaxSizeLimiter (maxSize) {
|
||||
})
|
||||
}
|
||||
|
||||
let warningEmitted = /** @type {boolean} */ (false)
|
||||
|
||||
/**
|
||||
* @typedef {Object} DecompressHandlerOptions
|
||||
* @property {number[]|Readonly<number[]>} [skipStatusCodes=[204, 304]] - List of status codes to skip decompression for
|
||||
@@ -550,15 +548,6 @@ class DecompressHandler extends DecoratorHandler {
|
||||
* @returns {Function} - Interceptor function
|
||||
*/
|
||||
function createDecompressInterceptor (options = {}) {
|
||||
// Emit experimental warning only once
|
||||
if (!warningEmitted) {
|
||||
process.emitWarning(
|
||||
'DecompressInterceptor is experimental and subject to change',
|
||||
'ExperimentalWarning'
|
||||
)
|
||||
warningEmitted = true
|
||||
}
|
||||
|
||||
return (dispatch) => {
|
||||
return (opts, handler) => {
|
||||
if (opts.method === 'HEAD') {
|
||||
|
||||
+4
-1
@@ -4,6 +4,7 @@ const diagnosticsChannel = require('node:diagnostics_channel')
|
||||
const util = require('../core/util')
|
||||
const DeduplicationHandler = require('../handler/deduplication-handler')
|
||||
const { getInterceptorOrigin, normalizeHeaders, makeCacheKey, makeDeduplicationKey } = require('../util/cache.js')
|
||||
const { kInterceptorKind } = require('../core/symbols.js')
|
||||
|
||||
const pendingRequestsChannel = diagnosticsChannel.channel('undici:request:pending-requests')
|
||||
|
||||
@@ -57,7 +58,7 @@ module.exports = (opts = {}) => {
|
||||
*/
|
||||
const pendingRequests = new Map()
|
||||
|
||||
return (dispatch, interceptorOrigin) => {
|
||||
const interceptor = (dispatch, interceptorOrigin) => {
|
||||
return (opts, handler) => {
|
||||
const requestOrigin = getInterceptorOrigin(opts, interceptorOrigin)
|
||||
if (!requestOrigin || opts.upgrade || methods.includes(opts.method) === false) {
|
||||
@@ -115,4 +116,6 @@ module.exports = (opts = {}) => {
|
||||
return dispatch(opts, deduplicationHandler)
|
||||
}
|
||||
}
|
||||
interceptor[kInterceptorKind] = 'deduplicate'
|
||||
return interceptor
|
||||
}
|
||||
+4
-1
@@ -1,9 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const RedirectHandler = require('../handler/redirect-handler')
|
||||
const { kInterceptorKind } = require('../core/symbols.js')
|
||||
|
||||
function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections, throwOnMaxRedirect: defaultThrowOnMaxRedirect, stripHeadersOnRedirect: defaultStripHeadersOnRedirect, stripHeadersOnCrossOriginRedirect: defaultStripHeadersOnCrossOriginRedirect } = {}) {
|
||||
return (dispatch) => {
|
||||
const interceptor = (dispatch) => {
|
||||
return function Intercept (opts, handler) {
|
||||
const { maxRedirections = defaultMaxRedirections, throwOnMaxRedirect = defaultThrowOnMaxRedirect, stripHeadersOnRedirect = defaultStripHeadersOnRedirect, stripHeadersOnCrossOriginRedirect = defaultStripHeadersOnCrossOriginRedirect, ...rest } = opts
|
||||
|
||||
@@ -16,6 +17,8 @@ function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections, t
|
||||
return dispatch(dispatchOpts, redirectHandler)
|
||||
}
|
||||
}
|
||||
interceptor[kInterceptorKind] = 'redirect'
|
||||
return interceptor
|
||||
}
|
||||
|
||||
module.exports = createRedirectInterceptor
|
||||
Vendored
+1
-1
@@ -650,7 +650,7 @@ function isInvalidOrWildcardVaryHeader (varyHeader) {
|
||||
|
||||
/**
|
||||
* Note: this deviates from the spec a little. Empty etags ("", W/"") are valid,
|
||||
* however, including them in cached resposnes serves little to no purpose.
|
||||
* however, including them in cached responses serves little to no purpose.
|
||||
*
|
||||
* @see https://www.rfc-editor.org/rfc/rfc9110.html#name-etag
|
||||
*
|
||||
|
||||
Vendored
+1
-1
@@ -194,7 +194,7 @@ function refreshTimeout () {
|
||||
// method (e.g. mocked timers in tests).
|
||||
if (fastNowTimeout?.refresh) {
|
||||
fastNowTimeout.refresh()
|
||||
// fastNowTimeout is not instantiated yet or refresh is not availabe,
|
||||
// fastNowTimeout is not instantiated yet or refresh is not available,
|
||||
// create a new Timer.
|
||||
} else {
|
||||
clearTimeout(fastNowTimeout)
|
||||
|
||||
+6
-13
@@ -163,19 +163,12 @@ class FormData {
|
||||
}
|
||||
|
||||
[nodeUtil.inspect.custom] (depth, options) {
|
||||
const state = this.#state.reduce((a, b) => {
|
||||
if (a[b.name]) {
|
||||
if (Array.isArray(a[b.name])) {
|
||||
a[b.name].push(b.value)
|
||||
} else {
|
||||
a[b.name] = [a[b.name], b.value]
|
||||
}
|
||||
} else {
|
||||
a[b.name] = b.value
|
||||
}
|
||||
|
||||
return a
|
||||
}, { __proto__: null })
|
||||
const state = Object.groupBy(this.#state, ({ name }) => name)
|
||||
for (const [name, entries] of Object.entries(state)) {
|
||||
state[name] = entries.length === 1
|
||||
? entries[0].value
|
||||
: entries.map(({ value }) => value)
|
||||
}
|
||||
|
||||
options.depth ??= depth
|
||||
options.colors ??= true
|
||||
|
||||
+20
-1
@@ -59,7 +59,7 @@ const {
|
||||
const EE = require('node:events')
|
||||
const { Readable, pipeline, finished, isErrored, isReadable } = require('node:stream')
|
||||
const { addAbortListener, bufferToLowerCasedHeaderName } = require('../../core/util')
|
||||
const { SocketError } = require('../../core/errors')
|
||||
const { SocketError, InformationalError } = require('../../core/errors')
|
||||
const { dataURLProcessor, serializeAMimeType, minimizeSupportedMimeType } = require('./data-url')
|
||||
const { getGlobalDispatcher } = require('../../global')
|
||||
const { webidl } = require('../webidl')
|
||||
@@ -2333,6 +2333,10 @@ async function httpNetworkFetch (
|
||||
}
|
||||
}
|
||||
|
||||
// The response will be exposed without a body, so any content the
|
||||
// server sends is disregarded (see main fetch step 19).
|
||||
this.nullBodyStatus = nullBodyStatus.includes(status)
|
||||
|
||||
this.body = new Readable({ read: () => controller.resume() })
|
||||
|
||||
const onError = (err) => this.onResponseError(controller, err)
|
||||
@@ -2352,6 +2356,14 @@ async function httpNetworkFetch (
|
||||
},
|
||||
|
||||
onResponseData (controller, chunk) {
|
||||
if (this.nullBodyStatus) {
|
||||
// The server sent content in a response that must not have any.
|
||||
// Nobody can read it, so close the connection instead of waiting
|
||||
// for the server to finish sending it.
|
||||
controller.abort(new InformationalError('response with null body status has content'))
|
||||
return
|
||||
}
|
||||
|
||||
if (fetchParams.controller.dump) {
|
||||
return
|
||||
}
|
||||
@@ -2391,6 +2403,13 @@ async function httpNetworkFetch (
|
||||
fetchParams.controller.off('terminated', this.abort)
|
||||
}
|
||||
|
||||
if (this.nullBodyStatus) {
|
||||
// The response has no body, so a failure while receiving the
|
||||
// disregarded content must not turn it into a network error.
|
||||
this.body?.destroy()
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
request.mode === 'websocket' &&
|
||||
allowH2 !== false &&
|
||||
|
||||
+2
-2
@@ -560,7 +560,7 @@ function stripURLForReferrer (url, originOnly = false) {
|
||||
return url
|
||||
}
|
||||
|
||||
const isPotentialleTrustworthyIPv4 = RegExp.prototype.test
|
||||
const isPotentiallyTrustworthyIPv4 = RegExp.prototype.test
|
||||
.bind(/^127\.(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){2}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)$/)
|
||||
|
||||
const isPotentiallyTrustworthyIPv6 = RegExp.prototype.test
|
||||
@@ -583,7 +583,7 @@ function isOriginIPPotentiallyTrustworthy (origin) {
|
||||
}
|
||||
|
||||
// IPv4
|
||||
return isPotentialleTrustworthyIPv4(origin)
|
||||
return isPotentiallyTrustworthyIPv4(origin)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+63
-22
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "undici",
|
||||
"version": "8.12.4",
|
||||
"version": "8.13.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "undici",
|
||||
"version": "8.12.4",
|
||||
"version": "8.13.1",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@fastify/busboy": "3.2.4",
|
||||
"@fastify/busboy": "3.2.5",
|
||||
"@matteo.collina/tspl": "^0.2.0",
|
||||
"@metcoder95/https-pem": "^1.0.0",
|
||||
"@sinonjs/fake-timers": "^12.0.0",
|
||||
@@ -1131,20 +1131,37 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/config-array": {
|
||||
"version": "0.23.5",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.5.tgz",
|
||||
"integrity": "sha512-Y3kKLvC1dvTOT+oGlqNQ1XLqK6D1HU2YXPc52NmAlJZbMMWDzGYXMiPRJ8TYD39muD/OTjlZmNJ4ib7dvSrMBA==",
|
||||
"version": "0.23.6",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.6.tgz",
|
||||
"integrity": "sha512-WrTH7nioI9QPY4NZGnsywmecswJdgeq4BCM76qok9VgjTO29ZgUzUvcuJLVPYVQM4uDbaPBU0M33R9DIxI8X3w==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@eslint/object-schema": "^3.0.5",
|
||||
"debug": "^4.3.1",
|
||||
"minimatch": "^10.2.4"
|
||||
"minimatch": "^11.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/config-array/node_modules/minimatch": {
|
||||
"version": "11.0.8",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.8.tgz",
|
||||
"integrity": "sha512-nFQuYSTVrGvysVBps5Ih+0BdnYFN/Cj3C816r6+p7yK+FHrVLGE4O4N9AFwykrlNlvM2HYt+Rad1Uiro6h88Ig==",
|
||||
"dev": true,
|
||||
"license": "BlueOak-1.0.0",
|
||||
"dependencies": {
|
||||
"@isaacs/nonrecursive-glob-match": "^1.1.0",
|
||||
"brace-expansion": "^5.0.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/config-helpers": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.7.0.tgz",
|
||||
@@ -1196,9 +1213,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@fastify/busboy": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-3.2.4.tgz",
|
||||
"integrity": "sha512-lQS8xcXT54rdJb+wlG/Q7SMSdtkZEpLPHooSDUZyyZm9LJD7X1kONPhVoPaHq+dsPtWUGGLIz9gBNhs9qKbylw==",
|
||||
"version": "3.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-3.2.5.tgz",
|
||||
"integrity": "sha512-y8MTAeBlEQUNVnskmZQwpseZN3EgCksQNOULlfxWY6o6VEqh01+oExMgbM7gN6YLQ8pNDYeweNPKJRt8jQm2ZQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
@@ -1297,6 +1314,13 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/nonrecursive-glob-match": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz",
|
||||
"integrity": "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==",
|
||||
"dev": true,
|
||||
"license": "BlueOak-1.0.0"
|
||||
},
|
||||
"node_modules/@istanbuljs/load-nyc-config": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
||||
@@ -4557,9 +4581,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint": {
|
||||
"version": "10.13.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-10.13.0.tgz",
|
||||
"integrity": "sha512-UohDjD4zSzEwhf58M3O7vc/ycc8O1I7dNlhtD0WxE8Px8EHNJKtUwzBqrzeGhisRuv2ag4sAYswszCJRgKXYUg==",
|
||||
"version": "10.15.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-10.15.0.tgz",
|
||||
"integrity": "sha512-+5Wg4p+ze3sG1WErYgUO/3H1IQIfFBymVUA0Fo/XTeBOLS6UQIUekpSJ8sdRkn7O7wjh84b55w/roqavH2aScg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
@@ -4568,11 +4592,11 @@
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.8.0",
|
||||
"@eslint-community/regexpp": "^4.12.2",
|
||||
"@eslint/config-array": "^0.23.5",
|
||||
"@eslint/config-array": "^0.23.6",
|
||||
"@eslint/config-helpers": "^0.7.0",
|
||||
"@eslint/core": "^1.2.1",
|
||||
"@eslint/plugin-kit": "^0.7.3",
|
||||
"@humanfs/node": "^0.16.6",
|
||||
"@humanfs/node": "^0.16.8",
|
||||
"@humanwhocodes/module-importer": "^1.0.1",
|
||||
"@humanwhocodes/retry": "^0.4.2",
|
||||
"@types/estree": "^1.0.6",
|
||||
@@ -4593,7 +4617,7 @@
|
||||
"imurmurhash": "^0.1.4",
|
||||
"is-glob": "^4.0.0",
|
||||
"json-stable-stringify-without-jsonify": "^1.0.1",
|
||||
"minimatch": "^10.2.5",
|
||||
"minimatch": "^11.0.5",
|
||||
"natural-compare": "^1.4.0",
|
||||
"optionator": "^0.9.3"
|
||||
},
|
||||
@@ -4942,6 +4966,23 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/minimatch": {
|
||||
"version": "11.0.8",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.8.tgz",
|
||||
"integrity": "sha512-nFQuYSTVrGvysVBps5Ih+0BdnYFN/Cj3C816r6+p7yK+FHrVLGE4O4N9AFwykrlNlvM2HYt+Rad1Uiro6h88Ig==",
|
||||
"dev": true,
|
||||
"license": "BlueOak-1.0.0",
|
||||
"dependencies": {
|
||||
"@isaacs/nonrecursive-glob-match": "^1.1.0",
|
||||
"brace-expansion": "^5.0.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/p-locate": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz",
|
||||
@@ -7195,9 +7236,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/node-forge": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.4.2.tgz",
|
||||
"integrity": "sha512-rRtAR5XLJ8gCKd9du4qrKAsgCG1ObGP4gLeNJMa4vYSeq4bmBMOJk5IHkrviBV0q7uoAJlVd8HEQYQSVUb4FGQ==",
|
||||
"version": "1.4.3",
|
||||
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.4.3.tgz",
|
||||
"integrity": "sha512-P6wzfh6t70avmV8FrVEAd/36sOPJQ+hkaJVX1Laap9J/77m7M0eyozDvc8SwnDf4P7MP94gwbAAo0rg3YVXT+g==",
|
||||
"dev": true,
|
||||
"license": "(BSD-3-Clause OR GPL-2.0)",
|
||||
"engines": {
|
||||
@@ -9032,9 +9073,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.22.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.22.0.tgz",
|
||||
"integrity": "sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==",
|
||||
"version": "8.23.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.23.0.tgz",
|
||||
"integrity": "sha512-wCkmX8QMOrKjgO8HW2WyDbTSGeqkocxgDzS9iR79rEAexty6/2qzilx3Ag8Tqf9ykop3irLKle0MtVn5qjVnoQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
|
||||
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "undici",
|
||||
"version": "8.12.4",
|
||||
"version": "8.13.1",
|
||||
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
||||
"homepage": "https://undici.nodejs.org",
|
||||
"bugs": {
|
||||
@@ -93,7 +93,7 @@
|
||||
"test:node-test": "borp --timeout 180000 -p \"test/node-test/**/*.js\"",
|
||||
"test:tdd": "borp --timeout 180000 --expose-gc -p \"test/*.js\"",
|
||||
"test:tdd:node-test": "borp --timeout 180000 -p \"test/node-test/**/*.js\" -w",
|
||||
"test:typescript": "tsd && tsc test/imports/undici-import.ts --typeRoots ./types --noEmit && tsc ./types/*.d.ts --noEmit --typeRoots ./types",
|
||||
"test:typescript": "tsd && tsc test/imports/undici-import.ts --typeRoots ./types --noEmit && tsc -p tsconfig.types.json",
|
||||
"test:webidl": "borp --timeout 180000 -p \"test/webidl/*.js\"",
|
||||
"test:websocket": "borp --timeout 180000 -p \"test/websocket/**/*.js\"",
|
||||
"test:websocket:autobahn": "node test/autobahn/client.js",
|
||||
@@ -111,7 +111,7 @@
|
||||
"prepare": "husky && node ./scripts/platform-shell.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fastify/busboy": "3.2.4",
|
||||
"@fastify/busboy": "3.2.5",
|
||||
"@matteo.collina/tspl": "^0.2.0",
|
||||
"@metcoder95/https-pem": "^1.0.0",
|
||||
"@sinonjs/fake-timers": "^12.0.0",
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"typeRoots": ["./types"]
|
||||
},
|
||||
"include": ["types/**/*.d.ts"]
|
||||
}
|
||||
+1
-1
@@ -78,7 +78,7 @@ declare namespace RetryHandler {
|
||||
*/
|
||||
minTimeout?: number;
|
||||
/**
|
||||
* Factior to multiply the timeout factor between retries.
|
||||
* Factor to multiply the timeout factor between retries.
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof RetryOptions
|
||||
|
||||
Vendored
+660
-396
File diff suppressed because it is too large.
Load diff
@@ -2,5 +2,5 @@
|
||||
// Refer to tools/dep_updaters/update-undici.sh
|
||||
#ifndef SRC_UNDICI_VERSION_H_
|
||||
#define SRC_UNDICI_VERSION_H_
|
||||
#define UNDICI_VERSION "8.12.4"
|
||||
#define UNDICI_VERSION "8.13.1"
|
||||
#endif // SRC_UNDICI_VERSION_H_
|
||||
Reference in new issue
Block a user