From f12c65077408d7fcc6b2d36dd29ba5db1a72d244 Mon Sep 17 00:00:00 2001 From: RomanxTheLast Date: Sun, 28 Jul 2024 13:45:09 +0000 Subject: [PATCH] Add async to the handleRequest chain in HttpServer (!387) The httpListeners are promise based but they aren't awaited when handling the request. I found this while implementing another version of HttpServer in a mod but couldn't actually find where this would cause an issue so feel free to close this if you think it's not worth it. Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/387 Co-authored-by: RomanxTheLast Co-committed-by: RomanxTheLast (cherry picked from commit 398bf4344472fd930ce46f7583429d05fda14451) --- project/src/servers/HttpServer.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project/src/servers/HttpServer.ts b/project/src/servers/HttpServer.ts index 306bb374..6f461af4 100644 --- a/project/src/servers/HttpServer.ts +++ b/project/src/servers/HttpServer.ts @@ -39,8 +39,8 @@ export class HttpServer { /* create server */ const httpServer: Server = http.createServer(); - httpServer.on("request", (req, res) => { - this.handleRequest(req, res); + httpServer.on("request", async (req, res) => { + await this.handleRequest(req, res); }); /* Config server to listen on a port */ @@ -65,7 +65,7 @@ export class HttpServer { this.webSocketServer.setupWebSocket(httpServer); } - protected handleRequest(req: IncomingMessage, resp: ServerResponse): void { + protected async handleRequest(req: IncomingMessage, resp: ServerResponse): Promise { // Pull sessionId out of cookies and store inside app context const sessionId = this.getCookies(req).PHPSESSID; this.applicationContext.addValue(ContextVariableType.SESSION_ID, sessionId); @@ -93,7 +93,7 @@ export class HttpServer { for (const listener of this.httpListeners) { if (listener.canHandle(sessionId, req)) { - listener.handle(sessionId, req, resp); + await listener.handle(sessionId, req, resp); break; } }