Reduced buffer memory leaks and improved performace by using streams after header processing
This commit is contained in:
parent
6bc064b474
commit
d75c6ce955
1 changed files with 6 additions and 2 deletions
8
index.js
8
index.js
|
@ -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});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue