Reduced buffer memory leaks and improved performace by using streams after header processing

This commit is contained in:
Dorian Niemiec 2024-02-16 02:32:10 +01:00
parent 6bc064b474
commit d75c6ce955

View file

@ -101,7 +101,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
var headerendline = -1; var headerendline = -1;
var cned = false; var cned = false;
var dataHandler = function (data) { var dataHandler = function (data) {
buffer += data.toString("latin1"); if (!cned) buffer += data.toString("latin1");
var m = null; var m = null;
if (!cned) m = buffer.match(/(?:\r\n\r\n|\n\r\n\r|\n\n|\r\r)/); if (!cned) m = buffer.match(/(?:\r\n\r\n|\n\r\n\r|\n\n|\r\r)/);
if (!cned && m) { if (!cned && m) {
@ -161,7 +161,11 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
return; return;
} }
} else { } else {
if (cned && !res.finished) res.write(data); if (cned && !res.finished) {
res.write(data);
interpreter.stdout.removeListener("data", dataHandler);
interpreter.stdout.pipe(res, {end: false});
}
} }
}; };