Fix GreenRhombus cutting off the final part of response
This commit is contained in:
parent
d7bae6df69
commit
6f46b52045
1 changed files with 28 additions and 11 deletions
39
index.js
39
index.js
|
@ -250,31 +250,48 @@ function createFastCGIHandler(options) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var stdoutPushEvent = new EventEmitter();
|
||||||
|
|
||||||
function stdoutPush(data) {
|
function stdoutPush(data) {
|
||||||
var toResume = (stdoutBuffer.length == 0);
|
|
||||||
if(data === null) {
|
if(data === null) {
|
||||||
stdoutToEnd = true;
|
stdoutToEnd = true;
|
||||||
} else {
|
} else {
|
||||||
stdoutBuffer = Buffer.concat([stdoutBuffer, Buffer.from(data)]);
|
stdoutBuffer = Buffer.concat([stdoutBuffer, Buffer.from(data)]);
|
||||||
}
|
}
|
||||||
if(toResume) emulatedStdout.resume();
|
stdoutPushEvent.emit("ready");
|
||||||
|
emulatedStdout.resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
function stdoutRead(n, callback) {
|
||||||
|
if(stdoutBuffer.length == 0 && stdoutToEnd) {
|
||||||
|
callback(Buffer.alloc(0));
|
||||||
|
} else if(n != 0) {
|
||||||
|
var handler = function() {
|
||||||
|
if(n > stdoutBuffer.length && !stdoutToEnd) {
|
||||||
|
stdoutPushEvent.once("ready", handler);
|
||||||
|
fs.writeFileSync("/tmp/fai", "");
|
||||||
|
} else {
|
||||||
|
var bytesToPush = Math.min(stdoutBuffer.length, n);
|
||||||
|
var bufferToPush = stdoutBuffer.subarray(0, bytesToPush);
|
||||||
|
stdoutBuffer = stdoutBuffer.subarray(bytesToPush);
|
||||||
|
callback(bufferToPush);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
handler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var stdoutBuffer = Buffer.alloc(0);
|
var stdoutBuffer = Buffer.alloc(0);
|
||||||
var stdoutToEnd = false;
|
var stdoutToEnd = false;
|
||||||
var emulatedStdout = new stream.Readable({
|
var emulatedStdout = new stream.Readable({
|
||||||
read: function (n) {
|
read: function (n) {
|
||||||
if(stdoutBuffer.length == 0 && stdoutToEnd) {
|
var s = this;
|
||||||
this.push(null);
|
stdoutRead(n, function(buffer) {
|
||||||
} else if (stdoutBuffer.length != 0 && n != 0) {
|
s.push(buffer.length > 0 ? buffer : null);
|
||||||
var bytesToPush = Math.min(stdoutBuffer.length, n);
|
});
|
||||||
var bufferToPush = stdoutBuffer.subarray(0, bytesToPush);
|
|
||||||
stdoutBuffer = stdoutBuffer.subarray(bytesToPush);
|
|
||||||
this.push(bufferToPush);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emulatedStdout.pause();
|
emulatedStdout.pause(); //Reduce backpressure
|
||||||
|
|
||||||
var emulatedStderr = new stream.Readable({
|
var emulatedStderr = new stream.Readable({
|
||||||
read: function () {}
|
read: function () {}
|
||||||
|
|
Loading…
Reference in a new issue