Further cleanup of sendResponse()
This commit is contained in:
parent
f76ffc8f93
commit
50c2c55837
@ -92,10 +92,14 @@ export class SptHttpListener implements IHttpListener {
|
|||||||
): void {
|
): void {
|
||||||
const bodyInfo = this.getBodyInfo(body);
|
const bodyInfo = this.getBodyInfo(body);
|
||||||
|
|
||||||
// Check if this is a debug request, send only raw response without transformation
|
if (this.isDebugRequest(req)) {
|
||||||
if (req.headers.responsecompressed === "0") {
|
// Send only raw response without transformation
|
||||||
this.sendJson(resp, output, sessionID);
|
this.sendJson(resp, output, sessionID);
|
||||||
} else {
|
this.logRequest(req, output);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Not debug, minority of requests need a serializer to do the job (IMAGE/BUNDLE/NOTIFY)
|
// Not debug, minority of requests need a serializer to do the job (IMAGE/BUNDLE/NOTIFY)
|
||||||
const serialiser = this.serializers.find((x) => x.canHandle(output));
|
const serialiser = this.serializers.find((x) => x.canHandle(output));
|
||||||
if (serialiser) {
|
if (serialiser) {
|
||||||
@ -104,9 +108,26 @@ export class SptHttpListener implements IHttpListener {
|
|||||||
// No serializer can handle the request (majority of requests dont), zlib the output and send response back
|
// No serializer can handle the request (majority of requests dont), zlib the output and send response back
|
||||||
this.sendZlibJson(resp, output, sessionID);
|
this.sendZlibJson(resp, output, sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logRequest(req, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log request if enabled
|
/**
|
||||||
|
* Is request flagged as debug enabled
|
||||||
|
* @param req Incoming request
|
||||||
|
* @returns True if request is flagged as debug
|
||||||
|
*/
|
||||||
|
protected isDebugRequest(req: IncomingMessage): boolean {
|
||||||
|
return req.headers.responsecompressed === "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log request if enabled
|
||||||
|
* @param req Incoming message request
|
||||||
|
* @param output Output string
|
||||||
|
*/
|
||||||
|
protected logRequest(req: IncomingMessage, output: string): void {
|
||||||
|
//
|
||||||
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)}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user