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 <alex@romanx.co.uk> Co-committed-by: RomanxTheLast <alex@romanx.co.uk> (cherry picked from commit 398bf4344472fd930ce46f7583429d05fda14451)
This commit is contained in:
parent
c114d4285f
commit
f12c650774
@ -39,8 +39,8 @@ export class HttpServer {
|
|||||||
/* create server */
|
/* create server */
|
||||||
const httpServer: Server = http.createServer();
|
const httpServer: Server = http.createServer();
|
||||||
|
|
||||||
httpServer.on("request", (req, res) => {
|
httpServer.on("request", async (req, res) => {
|
||||||
this.handleRequest(req, res);
|
await this.handleRequest(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Config server to listen on a port */
|
/* Config server to listen on a port */
|
||||||
@ -65,7 +65,7 @@ export class HttpServer {
|
|||||||
this.webSocketServer.setupWebSocket(httpServer);
|
this.webSocketServer.setupWebSocket(httpServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected handleRequest(req: IncomingMessage, resp: ServerResponse): void {
|
protected async handleRequest(req: IncomingMessage, resp: ServerResponse): Promise<void> {
|
||||||
// Pull sessionId out of cookies and store inside app context
|
// Pull sessionId out of cookies and store inside app context
|
||||||
const sessionId = this.getCookies(req).PHPSESSID;
|
const sessionId = this.getCookies(req).PHPSESSID;
|
||||||
this.applicationContext.addValue(ContextVariableType.SESSION_ID, sessionId);
|
this.applicationContext.addValue(ContextVariableType.SESSION_ID, sessionId);
|
||||||
@ -93,7 +93,7 @@ export class HttpServer {
|
|||||||
|
|
||||||
for (const listener of this.httpListeners) {
|
for (const listener of this.httpListeners) {
|
||||||
if (listener.canHandle(sessionId, req)) {
|
if (listener.canHandle(sessionId, req)) {
|
||||||
listener.handle(sessionId, req, resp);
|
await listener.handle(sessionId, req, resp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user