MCPcopy
hub / github.com/socketio/socket.io / handleRequest

Method handleRequest

packages/engine.io/lib/server.ts:784–826  ·  view source on GitHub ↗

* Handles an Engine.IO HTTP request. * * @param {IncomingMessage} req * @param {ServerResponse} res

(req: IncomingMessage, res: ServerResponse)

Source from the content-addressed store, hash-verified

782 * @param {ServerResponse} res
783 */
784 public handleRequest(req: IncomingMessage, res: ServerResponse) {
785 debug('handling "%s" http request "%s"', req.method, req.url);
786 const engineRequest = req as EngineRequest;
787
788 this.prepare(engineRequest);
789 engineRequest.res = res;
790
791 const callback: ErrorCallback = (errorCode, errorContext) => {
792 if (errorCode !== undefined) {
793 this.emit("connection_error", {
794 req: engineRequest,
795 code: errorCode,
796 message: Server.errorMessages[errorCode],
797 context: errorContext,
798 });
799 abortRequest(res, errorCode, errorContext);
800 return;
801 }
802
803 if (engineRequest._query.sid) {
804 debug("setting new request for existing client");
805 this.clients[engineRequest._query.sid].transport.onRequest(
806 engineRequest,
807 );
808 } else {
809 const closeConnection = (errorCode, errorContext) =>
810 abortRequest(res, errorCode, errorContext);
811 this.handshake(
812 engineRequest._query.transport as TransportName,
813 engineRequest,
814 closeConnection,
815 );
816 }
817 };
818
819 this._applyMiddlewares(engineRequest, res, (err) => {
820 if (err) {
821 callback(Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" });
822 } else {
823 this.verify(engineRequest, false, callback);
824 }
825 });
826 }
827
828 /**
829 * Handles an Engine.IO HTTP Upgrade.

Callers 2

attachMethod · 0.95
handlerFunction · 0.45

Calls 4

prepareMethod · 0.95
debugFunction · 0.85
_applyMiddlewaresMethod · 0.80
callbackFunction · 0.50

Tested by

no test coverage detected