From 40839557c974486f38a66b626136dd85fd8930d3 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 14:55:53 +0200 Subject: [PATCH 01/27] http: expose websockets --- lib/http.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/http.js b/lib/http.js index 9fce02d6e3b3ac..4cd3b6f21d3e9c 100644 --- a/lib/http.js +++ b/lib/http.js @@ -27,6 +27,7 @@ const { ObjectDefineProperty, } = primordials; +const { CloseEvent, WebSocket, MessageEvent } = require('internal/deps/undici/undici'); const { validateInteger } = require('internal/validators'); const httpAgent = require('_http_agent'); const { ClientRequest } = require('_http_client'); @@ -126,6 +127,9 @@ module.exports = { OutgoingMessage, Server, ServerResponse, + WebSocket, + MessageEvent, + CloseEvent, createServer, validateHeaderName, validateHeaderValue, From 9dd678b44ed3534cc82dfd847933221b348ca537 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 15:05:41 +0200 Subject: [PATCH 02/27] test: add test for exposing websocket in http --- test/parallel/test-http-import-websocket.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/parallel/test-http-import-websocket.js diff --git a/test/parallel/test-http-import-websocket.js b/test/parallel/test-http-import-websocket.js new file mode 100644 index 00000000000000..38509ad54da004 --- /dev/null +++ b/test/parallel/test-http-import-websocket.js @@ -0,0 +1,9 @@ +'use strict'; + +const assert = require('assert'); +const { CloseEvent, WebSocket, MessageEvent } = require('node:http'); + +assert.strictEqual(typeof WebSocket, 'function'); +assert.strictEqual(typeof CloseEvent, 'function'); +assert.strictEqual(typeof MessageEvent, 'function'); + From a2e4f849527b7759b9a180257a3797c814b07a9a Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 17:43:52 +0200 Subject: [PATCH 03/27] http: add dynamic loading on first usage --- lib/http.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 4cd3b6f21d3e9c..c69c39777a0487 100644 --- a/lib/http.js +++ b/lib/http.js @@ -27,7 +27,6 @@ const { ObjectDefineProperty, } = primordials; -const { CloseEvent, WebSocket, MessageEvent } = require('internal/deps/undici/undici'); const { validateInteger } = require('internal/validators'); const httpAgent = require('_http_agent'); const { ClientRequest } = require('_http_client'); @@ -45,6 +44,7 @@ const { ServerResponse, } = require('_http_server'); let maxHeaderSize; +let WebSocket, MessageEvent, CloseEvent; /** * Returns a new instance of `http.Server`. @@ -117,6 +117,36 @@ function get(url, options, cb) { return req; } +/** + * Load WebSocket class from undici + * @returns {void} + */ +function loadWebSocket() { + if (!WebSocket) { + ({ WebSocket } = require('internal/deps/undici/undici')); + } +} + +/** + * Load MessageEvent class from undici + * @returns {void} + */ +function loadMessageEvent() { + if (!MessageEvent) { + ({ MessageEvent } = require('internal/deps/undici/undici')); + } +} + +/** + * Load CloseEvent class from undici + * @returns {void} + */ +function loadCloseEvent() { + if (!CloseEvent) { + ({ CloseEvent } = require('internal/deps/undici/undici')); + } +} + module.exports = { _connectionListener, METHODS: ArrayPrototypeSort(ArrayPrototypeSlice(methods)), @@ -166,3 +196,33 @@ ObjectDefineProperty(module.exports, 'globalAgent', { httpAgent.globalAgent = value; }, }); + +ObjectDefineProperty(module.exports, 'WebSocket', { + __proto__: null, + configurable: true, + enumerable: true, + get() { + loadWebSocket(); + return WebSocket; + } +}); + +ObjectDefineProperty(module.exports, 'CloseEvent', { + __proto__: null, + configurable: true, + enumerable: true, + get() { + loadCloseEvent(); + return CloseEvent; + } +}); + +ObjectDefineProperty(module.exports, 'MessageEvent', { + __proto__: null, + configurable: true, + enumerable: true, + get() { + loadMessageEvent(); + return MessageEvent; + } +}); From 0d5d120b91836dc571f4bf6ff3e1cd95d8fdf10d Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 17:44:31 +0200 Subject: [PATCH 04/27] test: extend test to compare strict with global --- test/parallel/test-http-import-websocket.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-http-import-websocket.js b/test/parallel/test-http-import-websocket.js index 38509ad54da004..26369d0f33824f 100644 --- a/test/parallel/test-http-import-websocket.js +++ b/test/parallel/test-http-import-websocket.js @@ -1,9 +1,14 @@ 'use strict'; +require('../common'); const assert = require('assert'); -const { CloseEvent, WebSocket, MessageEvent } = require('node:http'); +const { WebSocket: NodeHttpWebSocket, CloseEvent: NodeHttpCloseEvent, MessageEvent: NodeHttpMessageEvent } = require('node:http'); -assert.strictEqual(typeof WebSocket, 'function'); -assert.strictEqual(typeof CloseEvent, 'function'); -assert.strictEqual(typeof MessageEvent, 'function'); +assert.strictEqual(typeof NodeHttpWebSocket, 'function'); +assert.strictEqual(typeof NodeHttpCloseEvent, 'function'); +assert.strictEqual(typeof NodeHttpMessageEvent, 'function'); +// compare with global objects +assert.strictEqual(NodeHttpWebSocket, WebSocket); +assert.strictEqual(NodeHttpCloseEvent, CloseEvent); +assert.strictEqual(NodeHttpMessageEvent, MessageEvent); From e4b6558a3af382f516235496d53a461cc5f47dae Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 21:06:03 +0200 Subject: [PATCH 05/27] http: refactor to lazyload classes more effectively --- lib/http.js | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/lib/http.js b/lib/http.js index c69c39777a0487..eea5bcc1e19272 100644 --- a/lib/http.js +++ b/lib/http.js @@ -118,33 +118,14 @@ function get(url, options, cb) { } /** - * Load WebSocket class from undici - * @returns {void} + * Lazy loads WebSocket, CloseEvent and MessageEvent classes from undici + * @returns {Object} An object containing WebSocket, CloseEvent, and MessageEvent classes. */ -function loadWebSocket() { +function lazyWebSocket() { if (!WebSocket) { - ({ WebSocket } = require('internal/deps/undici/undici')); - } -} - -/** - * Load MessageEvent class from undici - * @returns {void} - */ -function loadMessageEvent() { - if (!MessageEvent) { - ({ MessageEvent } = require('internal/deps/undici/undici')); - } -} - -/** - * Load CloseEvent class from undici - * @returns {void} - */ -function loadCloseEvent() { - if (!CloseEvent) { - ({ CloseEvent } = require('internal/deps/undici/undici')); + ({ WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici')); } + return { WebSocket, CloseEvent, MessageEvent }; } module.exports = { @@ -202,7 +183,7 @@ ObjectDefineProperty(module.exports, 'WebSocket', { configurable: true, enumerable: true, get() { - loadWebSocket(); + lazyWebSocket(); return WebSocket; } }); @@ -212,7 +193,7 @@ ObjectDefineProperty(module.exports, 'CloseEvent', { configurable: true, enumerable: true, get() { - loadCloseEvent(); + lazyWebSocket(); return CloseEvent; } }); @@ -222,7 +203,7 @@ ObjectDefineProperty(module.exports, 'MessageEvent', { configurable: true, enumerable: true, get() { - loadMessageEvent(); + lazyWebSocket(); return MessageEvent; } }); From 576bdb0c076dffd76135666a5df05bf068e43086 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 21:07:19 +0200 Subject: [PATCH 06/27] test: update test/parallel/test-http-import-websocket.js Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> --- test/parallel/test-http-import-websocket.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/parallel/test-http-import-websocket.js b/test/parallel/test-http-import-websocket.js index 26369d0f33824f..0d9df908826853 100644 --- a/test/parallel/test-http-import-websocket.js +++ b/test/parallel/test-http-import-websocket.js @@ -4,9 +4,6 @@ require('../common'); const assert = require('assert'); const { WebSocket: NodeHttpWebSocket, CloseEvent: NodeHttpCloseEvent, MessageEvent: NodeHttpMessageEvent } = require('node:http'); -assert.strictEqual(typeof NodeHttpWebSocket, 'function'); -assert.strictEqual(typeof NodeHttpCloseEvent, 'function'); -assert.strictEqual(typeof NodeHttpMessageEvent, 'function'); // compare with global objects assert.strictEqual(NodeHttpWebSocket, WebSocket); From ecfd5eca5227f267ef9f92332790856f092f23a2 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Thu, 4 Jul 2024 21:21:12 +0200 Subject: [PATCH 07/27] http: refactor lazy loading function --- lib/http.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/http.js b/lib/http.js index eea5bcc1e19272..2b77eb80acbf5e 100644 --- a/lib/http.js +++ b/lib/http.js @@ -183,8 +183,7 @@ ObjectDefineProperty(module.exports, 'WebSocket', { configurable: true, enumerable: true, get() { - lazyWebSocket(); - return WebSocket; + return lazyWebSocket().WebSocket; } }); @@ -193,8 +192,7 @@ ObjectDefineProperty(module.exports, 'CloseEvent', { configurable: true, enumerable: true, get() { - lazyWebSocket(); - return CloseEvent; + return lazyWebSocket().CloseEvent; } }); @@ -203,7 +201,6 @@ ObjectDefineProperty(module.exports, 'MessageEvent', { configurable: true, enumerable: true, get() { - lazyWebSocket(); - return MessageEvent; + return lazyWebSocket().MessageEvent; } }); From 9b65b5b61dcc06fd1c4ef5dbb8690b079cee1778 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Fri, 5 Jul 2024 10:11:22 +0200 Subject: [PATCH 08/27] docs: add websocket reference to http doc --- doc/api/http.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/api/http.md b/doc/api/http.md index 3557e22085f8f7..7e0d16e5018ad9 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4228,6 +4228,15 @@ added: Set the maximum number of idle HTTP parsers. +## `WebSocket` + + + +A browser-compatible implementation of [`WebSocket`][]. + [RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt [`'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`]: errors.md#err_http_content_length_mismatch [`'checkContinue'`]: #event-checkcontinue From 804276c780ba58295a9231ac6f8046d398c77383 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Fri, 5 Jul 2024 16:41:30 +0200 Subject: [PATCH 09/27] fix: fix linting errors from ci --- lib/http.js | 6 +++--- test/parallel/test-http-import-websocket.js | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/http.js b/lib/http.js index 2b77eb80acbf5e..e3e058141e7e85 100644 --- a/lib/http.js +++ b/lib/http.js @@ -184,7 +184,7 @@ ObjectDefineProperty(module.exports, 'WebSocket', { enumerable: true, get() { return lazyWebSocket().WebSocket; - } + }, }); ObjectDefineProperty(module.exports, 'CloseEvent', { @@ -193,7 +193,7 @@ ObjectDefineProperty(module.exports, 'CloseEvent', { enumerable: true, get() { return lazyWebSocket().CloseEvent; - } + }, }); ObjectDefineProperty(module.exports, 'MessageEvent', { @@ -202,5 +202,5 @@ ObjectDefineProperty(module.exports, 'MessageEvent', { enumerable: true, get() { return lazyWebSocket().MessageEvent; - } + }, }); diff --git a/test/parallel/test-http-import-websocket.js b/test/parallel/test-http-import-websocket.js index 0d9df908826853..5026d65108f03a 100644 --- a/test/parallel/test-http-import-websocket.js +++ b/test/parallel/test-http-import-websocket.js @@ -2,10 +2,13 @@ require('../common'); const assert = require('assert'); -const { WebSocket: NodeHttpWebSocket, CloseEvent: NodeHttpCloseEvent, MessageEvent: NodeHttpMessageEvent } = require('node:http'); +const { + WebSocket: NodeHttpWebSocket, + CloseEvent: NodeHttpCloseEvent, + MessageEvent: NodeHttpMessageEvent +} = require('node:http'); - -// compare with global objects +// Compare with global objects assert.strictEqual(NodeHttpWebSocket, WebSocket); assert.strictEqual(NodeHttpCloseEvent, CloseEvent); assert.strictEqual(NodeHttpMessageEvent, MessageEvent); From 6e1cb1d2e8e8727d1955795df3309edc49be8e57 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 14:00:40 +0200 Subject: [PATCH 10/27] http: prevent global override Co-authored-by: Matteo Collina --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index e3e058141e7e85..0447dcdf75ecad 100644 --- a/lib/http.js +++ b/lib/http.js @@ -123,7 +123,7 @@ function get(url, options, cb) { */ function lazyWebSocket() { if (!WebSocket) { - ({ WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici')); + const { WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici'); } return { WebSocket, CloseEvent, MessageEvent }; } From a9c915ea12bc604df4cf4ddd640463f702960b3d Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 14:01:39 +0200 Subject: [PATCH 11/27] docs: put placeholder version Co-authored-by: Matteo Collina --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index 7e0d16e5018ad9..c6d707e891978e 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4232,7 +4232,7 @@ Set the maximum number of idle HTTP parsers. A browser-compatible implementation of [`WebSocket`][]. From c80014bcce9aab130641e403cde76d8ebbe27ce4 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 14:18:06 +0200 Subject: [PATCH 12/27] http: add return in scope --- lib/http.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 0447dcdf75ecad..88b0718750db9f 100644 --- a/lib/http.js +++ b/lib/http.js @@ -119,11 +119,12 @@ function get(url, options, cb) { /** * Lazy loads WebSocket, CloseEvent and MessageEvent classes from undici - * @returns {Object} An object containing WebSocket, CloseEvent, and MessageEvent classes. + * @returns {object} An object containing WebSocket, CloseEvent, and MessageEvent classes. */ function lazyWebSocket() { if (!WebSocket) { const { WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici'); + return { WebSocket, CloseEvent, MessageEvent }; } return { WebSocket, CloseEvent, MessageEvent }; } From b529947601cbbf4504b20ee88a78e48f6eb0c19b Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 14:18:26 +0200 Subject: [PATCH 13/27] docs: fix linter errors --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index c6d707e891978e..cfb3e378f2502f 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4235,7 +4235,7 @@ added: - REPLACEME --> -A browser-compatible implementation of [`WebSocket`][]. +A browser-compatible implementation of \[`WebSocket`]\[]. [RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt [`'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`]: errors.md#err_http_content_length_mismatch From 29e1861bc6604a073fbe62a43e421619f0c4ca2b Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 21:04:00 +0200 Subject: [PATCH 14/27] http: update with suggestion to rename var Co-authored-by: Matteo Collina --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 88b0718750db9f..f49f6a77296e33 100644 --- a/lib/http.js +++ b/lib/http.js @@ -44,7 +44,7 @@ const { ServerResponse, } = require('_http_server'); let maxHeaderSize; -let WebSocket, MessageEvent, CloseEvent; +let undici; /** * Returns a new instance of `http.Server`. From 067782d5ad1fb38505313c73db3db8c95385e428 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 21:04:34 +0200 Subject: [PATCH 15/27] http: update return accordingly Co-authored-by: Matteo Collina --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index f49f6a77296e33..2e1f23d8b5f3f0 100644 --- a/lib/http.js +++ b/lib/http.js @@ -126,7 +126,7 @@ function lazyWebSocket() { const { WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici'); return { WebSocket, CloseEvent, MessageEvent }; } - return { WebSocket, CloseEvent, MessageEvent }; + return undici; } module.exports = { From fc9a869b6dac557694adf5fe7bed338cad21b858 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 21:08:13 +0200 Subject: [PATCH 16/27] docs: remove escaping Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index cfb3e378f2502f..82bccbcf8cfe4e 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4235,7 +4235,7 @@ added: - REPLACEME --> -A browser-compatible implementation of \[`WebSocket`]\[]. +A browser-compatible implementation of [`WebSocket`][]. [RFC 8187]: https://www.rfc-editor.org/rfc/rfc8187.txt [`'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`]: errors.md#err_http_content_length_mismatch From 9aa63b090cfd05609799a5c51f4ad006cbe1530f Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 21:10:35 +0200 Subject: [PATCH 17/27] docs: add link at the bottom of the page --- doc/api/http.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/http.md b/doc/api/http.md index 82bccbcf8cfe4e..790763003cb453 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4268,6 +4268,7 @@ A browser-compatible implementation of [`WebSocket`][]. [`http.get()`]: #httpgetoptions-callback [`http.globalAgent`]: #httpglobalagent [`http.request()`]: #httprequestoptions-callback +[`http.WebSocket`]: #websocket [`message.headers`]: #messageheaders [`message.socket`]: #messagesocket [`message.trailers`]: #messagetrailers From 20789fba78cf5bd9da5ec8013baab509c1c61207 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 21:56:42 +0200 Subject: [PATCH 18/27] fix: fix linter docs --- doc/api/http.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 790763003cb453..c30f8ea5d33750 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4246,13 +4246,14 @@ A browser-compatible implementation of [`WebSocket`][]. [`'upgrade'`]: #event-upgrade [`--insecure-http-parser`]: cli.md#--insecure-http-parser [`--max-http-header-size`]: cli.md#--max-http-header-sizesize -[`Agent`]: #class-httpagent +[`Agent`]: #class- [`Buffer.byteLength()`]: buffer.md#static-method-bufferbytelengthstring-encoding [`Duplex`]: stream.md#class-streamduplex [`HPE_HEADER_OVERFLOW`]: errors.md#hpe_header_overflow [`Headers`]: globals.md#class-headers [`TypeError`]: errors.md#class-typeerror [`URL`]: url.md#the-whatwg-url-api +[`WebSocket`]: #websocket [`agent.createConnection()`]: #agentcreateconnectionoptions-callback [`agent.getName()`]: #agentgetnameoptions [`destroy()`]: #agentdestroy @@ -4268,7 +4269,6 @@ A browser-compatible implementation of [`WebSocket`][]. [`http.get()`]: #httpgetoptions-callback [`http.globalAgent`]: #httpglobalagent [`http.request()`]: #httprequestoptions-callback -[`http.WebSocket`]: #websocket [`message.headers`]: #messageheaders [`message.socket`]: #messagesocket [`message.trailers`]: #messagetrailers From b5e09314ce76436ad93eb5dafcf3a8390030730e Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 21:57:20 +0200 Subject: [PATCH 19/27] http: revert suggestion to fix errors --- lib/http.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/http.js b/lib/http.js index 2e1f23d8b5f3f0..88b0718750db9f 100644 --- a/lib/http.js +++ b/lib/http.js @@ -44,7 +44,7 @@ const { ServerResponse, } = require('_http_server'); let maxHeaderSize; -let undici; +let WebSocket, MessageEvent, CloseEvent; /** * Returns a new instance of `http.Server`. @@ -126,7 +126,7 @@ function lazyWebSocket() { const { WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici'); return { WebSocket, CloseEvent, MessageEvent }; } - return undici; + return { WebSocket, CloseEvent, MessageEvent }; } module.exports = { From d3df8975018fe159bdf2c24cd8837e6459c10b04 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sat, 6 Jul 2024 22:27:47 +0200 Subject: [PATCH 20/27] fix: revert broken link --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index c30f8ea5d33750..478886676fab23 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4246,7 +4246,7 @@ A browser-compatible implementation of [`WebSocket`][]. [`'upgrade'`]: #event-upgrade [`--insecure-http-parser`]: cli.md#--insecure-http-parser [`--max-http-header-size`]: cli.md#--max-http-header-sizesize -[`Agent`]: #class- +[`Agent`]: #class-httpagent [`Buffer.byteLength()`]: buffer.md#static-method-bufferbytelengthstring-encoding [`Duplex`]: stream.md#class-streamduplex [`HPE_HEADER_OVERFLOW`]: errors.md#hpe_header_overflow From 4d5f1803a290b3d67dd8fbdee5f8e5d68e16c7f2 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Sun, 7 Jul 2024 12:24:20 +0200 Subject: [PATCH 21/27] http: import all unidici in the lazy function --- lib/http.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/http.js b/lib/http.js index 88b0718750db9f..b87a35f880c464 100644 --- a/lib/http.js +++ b/lib/http.js @@ -44,7 +44,7 @@ const { ServerResponse, } = require('_http_server'); let maxHeaderSize; -let WebSocket, MessageEvent, CloseEvent; +let undici, WebSocket, MessageEvent, CloseEvent; /** * Returns a new instance of `http.Server`. @@ -122,11 +122,7 @@ function get(url, options, cb) { * @returns {object} An object containing WebSocket, CloseEvent, and MessageEvent classes. */ function lazyWebSocket() { - if (!WebSocket) { - const { WebSocket, CloseEvent, MessageEvent } = require('internal/deps/undici/undici'); - return { WebSocket, CloseEvent, MessageEvent }; - } - return { WebSocket, CloseEvent, MessageEvent }; + return undici ? undici : undici = require('internal/deps/undici/undici'); } module.exports = { From 0c2c82b6c29085312cd095b1969a6223a1668b42 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Mon, 8 Jul 2024 13:08:09 +0200 Subject: [PATCH 22/27] http: remove additional export Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> --- lib/http.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/http.js b/lib/http.js index b87a35f880c464..d3badfe3ed6c5b 100644 --- a/lib/http.js +++ b/lib/http.js @@ -135,9 +135,6 @@ module.exports = { OutgoingMessage, Server, ServerResponse, - WebSocket, - MessageEvent, - CloseEvent, createServer, validateHeaderName, validateHeaderValue, From aeed70124be01361649498ec78c4a19e4e76b0e6 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Mon, 8 Jul 2024 13:09:04 +0200 Subject: [PATCH 23/27] http: remove unnecessary declaration that was used in module.exports Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index d3badfe3ed6c5b..57865272194bdd 100644 --- a/lib/http.js +++ b/lib/http.js @@ -44,7 +44,7 @@ const { ServerResponse, } = require('_http_server'); let maxHeaderSize; -let undici, WebSocket, MessageEvent, CloseEvent; +let undici; /** * Returns a new instance of `http.Server`. From 7209a896415cfa2fb62f7df5521244e000af2ad4 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Mon, 8 Jul 2024 13:10:22 +0200 Subject: [PATCH 24/27] http: replace ternary Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 57865272194bdd..26b93b319c2fca 100644 --- a/lib/http.js +++ b/lib/http.js @@ -122,7 +122,7 @@ function get(url, options, cb) { * @returns {object} An object containing WebSocket, CloseEvent, and MessageEvent classes. */ function lazyWebSocket() { - return undici ? undici : undici = require('internal/deps/undici/undici'); + return undici ??= require('internal/deps/undici/undici'); } module.exports = { From c928a97db3cbef4d5f6e804cecc695a66dcc1ddd Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Mon, 8 Jul 2024 13:10:53 +0200 Subject: [PATCH 25/27] http: rename function Co-authored-by: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 26b93b319c2fca..77852eeceafeab 100644 --- a/lib/http.js +++ b/lib/http.js @@ -121,7 +121,7 @@ function get(url, options, cb) { * Lazy loads WebSocket, CloseEvent and MessageEvent classes from undici * @returns {object} An object containing WebSocket, CloseEvent, and MessageEvent classes. */ -function lazyWebSocket() { +function lazyUndici() { return undici ??= require('internal/deps/undici/undici'); } From cf3e9a7bfc1d6d4ce26d3261b110c9e211ac5a17 Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Mon, 8 Jul 2024 13:13:02 +0200 Subject: [PATCH 26/27] http: rename function invocation --- lib/http.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/http.js b/lib/http.js index 77852eeceafeab..e264d1ceca1dce 100644 --- a/lib/http.js +++ b/lib/http.js @@ -177,7 +177,7 @@ ObjectDefineProperty(module.exports, 'WebSocket', { configurable: true, enumerable: true, get() { - return lazyWebSocket().WebSocket; + return lazyUndici().WebSocket; }, }); @@ -186,7 +186,7 @@ ObjectDefineProperty(module.exports, 'CloseEvent', { configurable: true, enumerable: true, get() { - return lazyWebSocket().CloseEvent; + return lazyUndici().CloseEvent; }, }); @@ -195,6 +195,6 @@ ObjectDefineProperty(module.exports, 'MessageEvent', { configurable: true, enumerable: true, get() { - return lazyWebSocket().MessageEvent; + return lazyUnidici().MessageEvent; }, }); From 5ca86a1686bcc3b64666df41f807c7b9902ca0de Mon Sep 17 00:00:00 2001 From: Natalia Venditto Date: Mon, 8 Jul 2024 13:17:37 +0200 Subject: [PATCH 27/27] http: fix typo in name function --- lib/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index e264d1ceca1dce..78bca4d37298e4 100644 --- a/lib/http.js +++ b/lib/http.js @@ -195,6 +195,6 @@ ObjectDefineProperty(module.exports, 'MessageEvent', { configurable: true, enumerable: true, get() { - return lazyUnidici().MessageEvent; + return lazyUndici().MessageEvent; }, });