aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node_modules/undici/lib/core
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-11 19:00:29 +0500
committerEgor Tensin <egor@tensin.name>2026-10-11 19:00:29 +0500
commit20cbf953d092f8a3d5d4126caea9c3c90b1d6f93 (patch)
treef2f5e770657d5252ef02b0aa417fc03eb9ca83c0 /node_modules/undici/lib/core
parentupdate my email (diff)
downloadcleanup-path-20cbf953d092f8a3d5d4126caea9c3c90b1d6f93.tar.gz
cleanup-path-20cbf953d092f8a3d5d4126caea9c3c90b1d6f93.zip
bump dependencies
Diffstat (limited to 'node_modules/undici/lib/core')
-rw-r--r--node_modules/undici/lib/core/request.js83
1 files changed, 80 insertions, 3 deletions
diff --git a/node_modules/undici/lib/core/request.js b/node_modules/undici/lib/core/request.js
index 4da6066..0b2b1a8 100644
--- a/node_modules/undici/lib/core/request.js
+++ b/node_modules/undici/lib/core/request.js
@@ -263,11 +263,77 @@ class Request {
}
}
- onUpgrade (statusCode, headers, socket) {
+ /**
+ * @param {number|null} statusCode
+ * @param {Buffer[]|null} headers
+ * @param {import('node:stream').Duplex} socket
+ * @param {string} [statusText]
+ */
+ onUpgrade (statusCode, headers, socket, statusText = '') {
+ this.onFinally()
+
assert(!this.aborted)
assert(!this.completed)
- return this[kHandler].onUpgrade(statusCode, headers, socket)
+ if (statusCode !== null) {
+ this.#publishUpgradeHeaders(statusCode, headers, statusText)
+ }
+
+ const result = this[kHandler].onUpgrade(statusCode, headers, socket)
+
+ if (!this.aborted) {
+ this.completed = true
+ if (statusCode !== null) {
+ this.#publishUpgradeTrailers()
+ }
+ }
+
+ return result
+ }
+
+ /**
+ * @param {number} statusCode
+ * @param {import('node:http2').IncomingHttpHeaders} headers
+ * @param {(headers: import('node:http2').IncomingHttpHeaders) => Buffer[]} parseHeaders
+ * @param {string} [statusText]
+ */
+ onUpgradeResponse (statusCode, headers, parseHeaders, statusText = '') {
+ assert(!this.aborted)
+ assert(this.completed)
+
+ if (channels.headers.hasSubscribers) {
+ this.#publishUpgradeHeaders(statusCode, parseHeaders(headers), statusText)
+ }
+ this.#publishUpgradeTrailers()
+ }
+
+ /**
+ * @param {Error} error
+ */
+ onUpgradeError (error) {
+ assert(!this.aborted)
+ assert(this.completed)
+
+ if (channels.error.hasSubscribers) {
+ channels.error.publish({ request: this, error })
+ }
+ }
+
+ /**
+ * @param {number} statusCode
+ * @param {Buffer[]} headers
+ * @param {string} statusText
+ */
+ #publishUpgradeHeaders (statusCode, headers, statusText) {
+ if (channels.headers.hasSubscribers) {
+ channels.headers.publish({ request: this, response: { statusCode, headers, statusText } })
+ }
+ }
+
+ #publishUpgradeTrailers () {
+ if (channels.trailers.hasSubscribers) {
+ channels.trailers.publish({ request: this, trailers: [] })
+ }
}
onComplete (trailers) {
@@ -350,7 +416,13 @@ function processHeader (request, key, val) {
} else if (typeof val[i] === 'object') {
throw new InvalidArgumentError(`invalid ${key} header`)
} else {
- arr.push(`${val[i]}`)
+ // Coerce primitives (and reject unsafe coercions such as functions
+ // with a crafted toString/Symbol.toPrimitive).
+ const str = `${val[i]}`
+ if (!isValidHeaderValue(str)) {
+ throw new InvalidArgumentError(`invalid ${key} header`)
+ }
+ arr.push(str)
}
}
val = arr
@@ -361,7 +433,12 @@ function processHeader (request, key, val) {
} else if (val === null) {
val = ''
} else {
+ // Coerce primitives (and reject unsafe coercions such as functions
+ // with a crafted toString/Symbol.toPrimitive).
val = `${val}`
+ if (!isValidHeaderValue(val)) {
+ throw new InvalidArgumentError(`invalid ${key} header`)
+ }
}
if (headerName === 'host') {