mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
http: expose websockets
PR-URL: https://github.com/nodejs/node/pull/53721 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
36
lib/http.js
36
lib/http.js
@@ -42,6 +42,7 @@ const {
|
||||
ServerResponse,
|
||||
} = require('_http_server');
|
||||
let maxHeaderSize;
|
||||
let undici;
|
||||
|
||||
/**
|
||||
* Returns a new instance of `http.Server`.
|
||||
@@ -114,6 +115,14 @@ function get(url, options, cb) {
|
||||
return req;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy loads WebSocket, CloseEvent and MessageEvent classes from undici
|
||||
* @returns {object} An object containing WebSocket, CloseEvent, and MessageEvent classes.
|
||||
*/
|
||||
function lazyUndici() {
|
||||
return undici ??= require('internal/deps/undici/undici');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
_connectionListener,
|
||||
METHODS: methods.toSorted(),
|
||||
@@ -160,3 +169,30 @@ ObjectDefineProperty(module.exports, 'globalAgent', {
|
||||
httpAgent.globalAgent = value;
|
||||
},
|
||||
});
|
||||
|
||||
ObjectDefineProperty(module.exports, 'WebSocket', {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return lazyUndici().WebSocket;
|
||||
},
|
||||
});
|
||||
|
||||
ObjectDefineProperty(module.exports, 'CloseEvent', {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return lazyUndici().CloseEvent;
|
||||
},
|
||||
});
|
||||
|
||||
ObjectDefineProperty(module.exports, 'MessageEvent', {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return lazyUndici().MessageEvent;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user