Updated sendResponse() to not run serialiser when sending debug request

This commit is contained in:
Dev 2024-10-08 22:27:36 +01:00
parent ed92c6802c
commit f76ffc8f93

View File

@ -76,8 +76,8 @@ export class SptHttpListener implements IHttpListener {
} }
/** /**
* Send http response to the client * Send HTTP response back to sender
* @param sessionID Player id * @param sessionID Player id making request
* @param req Incoming request * @param req Incoming request
* @param resp Outgoing response * @param resp Outgoing response
* @param body Buffer * @param body Buffer
@ -90,27 +90,23 @@ export class SptHttpListener implements IHttpListener {
body: Buffer, body: Buffer,
output: string, output: string,
): void { ): void {
const info = this.getBodyInfo(body); const bodyInfo = this.getBodyInfo(body);
let handled = false;
// Check if this is a debug request, if so just send the raw response without transformation // Check if this is a debug request, send only raw response without transformation
if (req.headers.responsecompressed === "0") { if (req.headers.responsecompressed === "0") {
this.sendJson(resp, output, sessionID); this.sendJson(resp, output, sessionID);
} } else {
// Not debug, minority of requests need a serializer to do the job (IMAGE/BUNDLE/NOTIFY)
// Attempt to use one of our serializers to do the job const serialiser = this.serializers.find((x) => x.canHandle(output));
for (const serializer of this.serializers) { if (serialiser) {
if (serializer.canHandle(output)) { serialiser.serialize(sessionID, req, resp, bodyInfo);
serializer.serialize(sessionID, req, resp, info); } else {
handled = true; // No serializer can handle the request (majority of requests dont), zlib the output and send response back
break; this.sendZlibJson(resp, output, sessionID);
} }
} }
// If no serializer can handle the request we zlib the output and send it
if (!handled) {
this.sendZlibJson(resp, output, sessionID);
}
// Log request if enabled
if (globalThis.G_LOG_REQUESTS) { if (globalThis.G_LOG_REQUESTS) {
const log = new Response(req.method, output); const log = new Response(req.method, output);
this.requestsLogger.info(`RESPONSE=${this.jsonUtil.serialize(log)}`); this.requestsLogger.info(`RESPONSE=${this.jsonUtil.serialize(log)}`);