diff --git a/deps/undici/src/lib/client.js b/deps/undici/src/lib/client.js index 1625b47eafe2aa..41fd4a753f8188 100644 --- a/deps/undici/src/lib/client.js +++ b/deps/undici/src/lib/client.js @@ -441,6 +441,7 @@ class Parser { this.keepAlive = '' this.contentLength = '' + this.connection = '' this.maxResponseSize = client[kMaxResponseSize] } @@ -616,6 +617,8 @@ 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 === 10 && key.toString().toLowerCase() === 'connection') { + this.connection += buf.toString() } else if (key.length === 14 && key.toString().toLowerCase() === 'content-length') { this.contentLength += buf.toString() } @@ -709,7 +712,11 @@ class Parser { assert.strictEqual(this.timeoutType, TIMEOUT_HEADERS) this.statusCode = statusCode - this.shouldKeepAlive = shouldKeepAlive + this.shouldKeepAlive = ( + shouldKeepAlive || + // Override llhttp value which does not allow keepAlive for HEAD. + (request.method === 'HEAD' && !socket[kReset] && this.connection.toLowerCase() === 'keep-alive') + ) if (this.statusCode >= 200) { const bodyTimeout = request.bodyTimeout != null @@ -739,7 +746,7 @@ class Parser { this.headers = [] this.headersSize = 0 - if (shouldKeepAlive && client[kPipelining]) { + if (this.shouldKeepAlive && client[kPipelining]) { const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null if (keepAliveTimeout != null) { @@ -769,7 +776,6 @@ class Parser { } if (request.method === 'HEAD') { - assert(socket[kReset]) return 1 } @@ -843,6 +849,7 @@ class Parser { this.bytesRead = 0 this.contentLength = '' this.keepAlive = '' + this.connection = '' assert(this.headers.length % 2 === 0) this.headers = [] @@ -1376,8 +1383,8 @@ function write (client, request) { socket[kReset] = true } - if (reset) { - socket[kReset] = true + if (reset != null) { + socket[kReset] = reset } if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) { diff --git a/deps/undici/src/lib/core/request.js b/deps/undici/src/lib/core/request.js index e8a8f2a43dcc0e..bee1a872960666 100644 --- a/deps/undici/src/lib/core/request.js +++ b/deps/undici/src/lib/core/request.js @@ -144,7 +144,7 @@ class Request { this.blocking = blocking == null ? false : blocking - this.reset = reset == null ? false : reset + this.reset = reset == null ? null : reset this.host = null diff --git a/deps/undici/src/lib/fetch/formdata.js b/deps/undici/src/lib/fetch/formdata.js index a0c9e2f9373944..a957a80e02af7c 100644 --- a/deps/undici/src/lib/fetch/formdata.js +++ b/deps/undici/src/lib/fetch/formdata.js @@ -259,7 +259,7 @@ function makeEntry (name, value, filename) { lastModified: value.lastModified } - value = value instanceof File + value = (NativeFile && value instanceof NativeFile) || value instanceof UndiciFile ? new File([value], filename, options) : new FileLike(value, filename, options) } diff --git a/deps/undici/src/lib/websocket/websocket.js b/deps/undici/src/lib/websocket/websocket.js index 366b6aa3e275ac..79c9be439c1fb4 100644 --- a/deps/undici/src/lib/websocket/websocket.js +++ b/deps/undici/src/lib/websocket/websocket.js @@ -309,23 +309,14 @@ class WebSocket extends EventTarget { // not throw an exception must increase the bufferedAmount attribute // by the length of data’s buffer in bytes. - const ab = new ArrayBuffer(data.byteLength) + const ab = Buffer.from(data, data.byteOffset, data.byteLength) - if (Buffer.isBuffer(data)) { - // new Buffer signature is deprecated - Buffer.from(ab).set(data) - } else { - new data.constructor(ab).set(data) - } - - const value = Buffer.from(ab) - - const frame = new WebsocketFrameSend(value) + const frame = new WebsocketFrameSend(ab) const buffer = frame.createFrame(opcodes.BINARY) - this.#bufferedAmount += value.byteLength + this.#bufferedAmount += ab.byteLength socket.write(buffer, () => { - this.#bufferedAmount -= value.byteLength + this.#bufferedAmount -= ab.byteLength }) } else if (isBlobLike(data)) { // If the WebSocket connection is established, and the WebSocket diff --git a/deps/undici/src/package.json b/deps/undici/src/package.json index 44e214624fbca7..02c3bf3857e8cd 100644 --- a/deps/undici/src/package.json +++ b/deps/undici/src/package.json @@ -1,6 +1,6 @@ { "name": "undici", - "version": "5.15.0", + "version": "5.15.1", "description": "An HTTP/1.1 client, written from scratch for Node.js", "homepage": "https://undici.nodejs.org", "bugs": { diff --git a/deps/undici/undici.js b/deps/undici/undici.js index 05bcef21645300..a3c7eb571b555b 100644 --- a/deps/undici/undici.js +++ b/deps/undici/undici.js @@ -6088,7 +6088,7 @@ var require_formdata = __commonJS({ type: value.type, lastModified: value.lastModified }; - value = value instanceof File ? new File([value], filename, options) : new FileLike(value, filename, options); + value = NativeFile && value instanceof NativeFile || value instanceof UndiciFile ? new File([value], filename, options) : new FileLike(value, filename, options); } } return { name, value }; @@ -7505,7 +7505,7 @@ var require_request2 = __commonJS({ this.origin = origin; this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent; this.blocking = blocking == null ? false : blocking; - this.reset = reset == null ? false : reset; + this.reset = reset == null ? null : reset; this.host = null; this.contentLength = null; this.contentType = null; @@ -8869,6 +8869,7 @@ var require_client = __commonJS({ this.bytesRead = 0; this.keepAlive = ""; this.contentLength = ""; + this.connection = ""; this.maxResponseSize = client[kMaxResponseSize]; } setTimeout(value, type) { @@ -9004,6 +9005,8 @@ var require_client = __commonJS({ const key = this.headers[len - 2]; if (key.length === 10 && key.toString().toLowerCase() === "keep-alive") { this.keepAlive += buf.toString(); + } else if (key.length === 10 && key.toString().toLowerCase() === "connection") { + this.connection += buf.toString(); } else if (key.length === 14 && key.toString().toLowerCase() === "content-length") { this.contentLength += buf.toString(); } @@ -9067,7 +9070,7 @@ var require_client = __commonJS({ } assert.strictEqual(this.timeoutType, TIMEOUT_HEADERS); this.statusCode = statusCode; - this.shouldKeepAlive = shouldKeepAlive; + this.shouldKeepAlive = shouldKeepAlive || request.method === "HEAD" && !socket[kReset] && this.connection.toLowerCase() === "keep-alive"; if (this.statusCode >= 200) { const bodyTimeout = request.bodyTimeout != null ? request.bodyTimeout : client[kBodyTimeout]; this.setTimeout(bodyTimeout, TIMEOUT_BODY); @@ -9089,7 +9092,7 @@ var require_client = __commonJS({ assert(this.headers.length % 2 === 0); this.headers = []; this.headersSize = 0; - if (shouldKeepAlive && client[kPipelining]) { + if (this.shouldKeepAlive && client[kPipelining]) { const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null; if (keepAliveTimeout != null) { const timeout = Math.min(keepAliveTimeout - client[kKeepAliveTimeoutThreshold], client[kKeepAliveMaxTimeout]); @@ -9112,7 +9115,6 @@ var require_client = __commonJS({ return -1; } if (request.method === "HEAD") { - assert(socket[kReset]); return 1; } if (statusCode < 200) { @@ -9168,6 +9170,7 @@ var require_client = __commonJS({ this.bytesRead = 0; this.contentLength = ""; this.keepAlive = ""; + this.connection = ""; assert(this.headers.length % 2 === 0); this.headers = []; this.headersSize = 0; @@ -9534,8 +9537,8 @@ var require_client = __commonJS({ if (upgrade || method === "CONNECT") { socket[kReset] = true; } - if (reset) { - socket[kReset] = true; + if (reset != null) { + socket[kReset] = reset; } if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) { socket[kReset] = true; @@ -14518,18 +14521,12 @@ var require_websocket = __commonJS({ this.#bufferedAmount -= value.byteLength; }); } else if (ArrayBuffer.isView(data)) { - const ab = new ArrayBuffer(data.byteLength); - if (Buffer.isBuffer(data)) { - Buffer.from(ab).set(data); - } else { - new data.constructor(ab).set(data); - } - const value = Buffer.from(ab); - const frame = new WebsocketFrameSend(value); + const ab = Buffer.from(data, data.byteOffset, data.byteLength); + const frame = new WebsocketFrameSend(ab); const buffer = frame.createFrame(opcodes.BINARY); - this.#bufferedAmount += value.byteLength; + this.#bufferedAmount += ab.byteLength; socket.write(buffer, () => { - this.#bufferedAmount -= value.byteLength; + this.#bufferedAmount -= ab.byteLength; }); } else if (isBlobLike(data)) { const frame = new WebsocketFrameSend(); diff --git a/src/undici_version.h b/src/undici_version.h index 40875d828fbd5a..184417ee3bff1d 100644 --- a/src/undici_version.h +++ b/src/undici_version.h @@ -2,5 +2,5 @@ // Refer to tools/update-undici.sh #ifndef SRC_UNDICI_VERSION_H_ #define SRC_UNDICI_VERSION_H_ -#define UNDICI_VERSION "5.15.0" +#define UNDICI_VERSION "5.15.1" #endif // SRC_UNDICI_VERSION_H_