engine.io
Advanced tools
@@ -248,10 +248,10 @@ import { EventEmitter } from "events"; | ||
| * | ||
| * @param {EngineRequest} req | ||
| * @param {IncomingMessage} req | ||
| * @param {ServerResponse} res | ||
| */ | ||
| handleRequest(req: EngineRequest, res: ServerResponse): void; | ||
| handleRequest(req: IncomingMessage, res: ServerResponse): void; | ||
| /** | ||
| * Handles an Engine.IO HTTP Upgrade. | ||
| */ | ||
| handleUpgrade(req: EngineRequest, socket: Duplex, upgradeHead: Buffer): void; | ||
| handleUpgrade(req: IncomingMessage, socket: Duplex, upgradeHead: Buffer): void; | ||
| /** | ||
@@ -258,0 +258,0 @@ * Called upon a ws.io connection. |
+33
-21
@@ -24,2 +24,6 @@ "use strict"; | ||
| } | ||
| // Object.hasOwn() was introduced in Node.js 16.9 | ||
| function hasOwn(obj, key) { | ||
| return Object.prototype.hasOwnProperty.call(obj, key); | ||
| } | ||
| class BaseServer extends events_1.EventEmitter { | ||
@@ -122,3 +126,3 @@ /** | ||
| if (sid) { | ||
| if (!this.clients.hasOwnProperty(sid)) { | ||
| if (!hasOwn(this.clients, sid)) { | ||
| debug('unknown sid "%s"', sid); | ||
@@ -212,5 +216,5 @@ return fn(Server.errors.UNKNOWN_SID, { | ||
| debug("closing all open clients"); | ||
| for (let i in this.clients) { | ||
| if (this.clients.hasOwnProperty(i)) { | ||
| this.clients[i].close(true); | ||
| for (const sid in this.clients) { | ||
| if (hasOwn(this.clients, sid)) { | ||
| this.clients[sid].close(true); | ||
| } | ||
@@ -322,2 +326,8 @@ } | ||
| async onWebTransportSession(session) { | ||
| if (this.middlewares.length > 0) { | ||
| // middlewares expect an IncomingMessage argument, which cannot be created from the WebTransport session object | ||
| // see also: https://github.com/fails-components/webtransport/issues/448 | ||
| debug("closing session since WebTransport is not compatible with middlewares"); | ||
| return session.close(); | ||
| } | ||
| const timeout = setTimeout(() => { | ||
@@ -363,3 +373,3 @@ debug("the client failed to establish a bidirectional stream in the given period"); | ||
| const sid = parseSessionId(value.data); | ||
| if (!sid) { | ||
| if (!sid || !hasOwn(this.clients, sid)) { | ||
| debug("invalid WebTransport handshake"); | ||
@@ -501,3 +511,3 @@ return session.close(); | ||
| * | ||
| * @param {EngineRequest} req | ||
| * @param {IncomingMessage} req | ||
| * @param {ServerResponse} res | ||
@@ -507,8 +517,9 @@ */ | ||
| debug('handling "%s" http request "%s"', req.method, req.url); | ||
| this.prepare(req); | ||
| req.res = res; | ||
| const engineRequest = req; | ||
| this.prepare(engineRequest); | ||
| engineRequest.res = res; | ||
| const callback = (errorCode, errorContext) => { | ||
| if (errorCode !== undefined) { | ||
| this.emit("connection_error", { | ||
| req, | ||
| req: engineRequest, | ||
| code: errorCode, | ||
@@ -521,12 +532,12 @@ message: Server.errorMessages[errorCode], | ||
| } | ||
| if (req._query.sid) { | ||
| if (engineRequest._query.sid) { | ||
| debug("setting new request for existing client"); | ||
| this.clients[req._query.sid].transport.onRequest(req); | ||
| this.clients[engineRequest._query.sid].transport.onRequest(engineRequest); | ||
| } | ||
| else { | ||
| const closeConnection = (errorCode, errorContext) => abortRequest(res, errorCode, errorContext); | ||
| this.handshake(req._query.transport, req, closeConnection); | ||
| this.handshake(engineRequest._query.transport, engineRequest, closeConnection); | ||
| } | ||
| }; | ||
| this._applyMiddlewares(req, res, (err) => { | ||
| this._applyMiddlewares(engineRequest, res, (err) => { | ||
| if (err) { | ||
@@ -536,3 +547,3 @@ callback(Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" }); | ||
| else { | ||
| this.verify(req, false, callback); | ||
| this.verify(engineRequest, false, callback); | ||
| } | ||
@@ -545,8 +556,9 @@ }); | ||
| handleUpgrade(req, socket, upgradeHead) { | ||
| this.prepare(req); | ||
| const res = new WebSocketResponse(req, socket); | ||
| const engineRequest = req; | ||
| this.prepare(engineRequest); | ||
| const res = new WebSocketResponse(engineRequest, socket); | ||
| const callback = (errorCode, errorContext) => { | ||
| if (errorCode !== undefined) { | ||
| this.emit("connection_error", { | ||
| req, | ||
| req: engineRequest, | ||
| code: errorCode, | ||
@@ -565,7 +577,7 @@ message: Server.errorMessages[errorCode], | ||
| // delegate to ws | ||
| this.ws.handleUpgrade(req, socket, head, (websocket) => { | ||
| this.onWebSocket(req, socket, websocket); | ||
| this.ws.handleUpgrade(engineRequest, socket, head, (websocket) => { | ||
| this.onWebSocket(engineRequest, socket, websocket); | ||
| }); | ||
| }; | ||
| this._applyMiddlewares(req, res, (err) => { | ||
| this._applyMiddlewares(engineRequest, res, (err) => { | ||
| if (err) { | ||
@@ -575,3 +587,3 @@ callback(Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" }); | ||
| else { | ||
| this.verify(req, true, callback); | ||
| this.verify(engineRequest, true, callback); | ||
| } | ||
@@ -578,0 +590,0 @@ }); |
@@ -38,3 +38,3 @@ import { Transport } from "../transport"; | ||
| */ | ||
| onDataRequest(req: any, res: any): void; | ||
| onDataRequest(req: any, res: any): any; | ||
| /** | ||
@@ -41,0 +41,0 @@ * Cleanup request. |
@@ -109,3 +109,4 @@ "use strict"; | ||
| if (isBinary && this.protocol === 4) { | ||
| return this.onError("invalid content"); | ||
| this.onError("invalid content"); | ||
| return res.writeStatus("400 Bad Request").end(); | ||
| } | ||
@@ -112,0 +113,0 @@ this.dataReq = req; |
@@ -97,3 +97,4 @@ "use strict"; | ||
| if (isBinary && this.protocol === 4) { | ||
| return this.onError("invalid content"); | ||
| this.onError("invalid content"); | ||
| return res.writeHead(400).end(); | ||
| } | ||
@@ -100,0 +101,0 @@ this.dataReq = req; |
+1
-1
| { | ||
| "name": "engine.io", | ||
| "version": "6.6.6", | ||
| "version": "6.6.7", | ||
| "description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
169572
0.53%4520
0.31%