Prevent data loss at end of the response
This commit is contained in:
parent
be5e86a59d
commit
067e54e8a2
2 changed files with 21 additions and 7 deletions
BIN
.index.js.swp
BIN
.index.js.swp
Binary file not shown.
24
index.js
24
index.js
|
@ -166,15 +166,13 @@ function createFastCGIHandler(options) {
|
||||||
var processedPacket = parseFastCGIPacket(packet);
|
var processedPacket = parseFastCGIPacket(packet);
|
||||||
if (processedPacket.requestID != requestID) return; //Drop the packet
|
if (processedPacket.requestID != requestID) return; //Drop the packet
|
||||||
if (processedPacket.type == STDOUT) {
|
if (processedPacket.type == STDOUT) {
|
||||||
emulatedStdout.push(processedPacket.content);
|
if(processedPacket.content.length > 0) emulatedStdout.push(processedPacket.content);
|
||||||
} else if (processedPacket.type == STDERR) {
|
} else if (processedPacket.type == STDERR) {
|
||||||
emulatedStderr.push(processedPacket.content);
|
if(processedPacket.content.length > 0) emulatedStderr.push(processedPacket.content);
|
||||||
} else if (processedPacket.type == END_REQUEST && processedPacket.content.length > 5) {
|
} else if (processedPacket.type == END_REQUEST && processedPacket.content.length > 5) {
|
||||||
if (typeof socket !== "undefined") socket.removeListener("data", fastCGISocketHandler);
|
if (typeof socket !== "undefined") socket.removeListener("data", fastCGISocketHandler);
|
||||||
var appStatus = processedPacket.content.readUInt32BE(0);
|
var appStatus = processedPacket.content.readUInt32BE(0);
|
||||||
var protocolStatus = processedPacket.content.readUInt8(4);
|
var protocolStatus = processedPacket.content.readUInt8(4);
|
||||||
emulatedStdout.push(null);
|
|
||||||
emulatedStderr.push(null);
|
|
||||||
if (protocolStatus != REQUEST_COMPLETE) {
|
if (protocolStatus != REQUEST_COMPLETE) {
|
||||||
var err = new Error("Unknown error");
|
var err = new Error("Unknown error");
|
||||||
if (protocolStatus == OVERLOADED) {
|
if (protocolStatus == OVERLOADED) {
|
||||||
|
@ -186,12 +184,28 @@ function createFastCGIHandler(options) {
|
||||||
} else if (protocolStatus == CANT_MPX_CONN) {
|
} else if (protocolStatus == CANT_MPX_CONN) {
|
||||||
err = new Error("Multiplexed connections not supported by the FastCGI application");
|
err = new Error("Multiplexed connections not supported by the FastCGI application");
|
||||||
}
|
}
|
||||||
|
emulatedStdout.push(null);
|
||||||
|
emulatedStderr.push(null);
|
||||||
|
if (emulatedStdout._readableState && emulatedStdout._readableState.length > 0 && emulatedStdout._readableState.flowing !== null) {
|
||||||
|
emulatedStdout.on("end", function() {
|
||||||
eventEmitter.emit("error", err);
|
eventEmitter.emit("error", err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
eventEmitter.emit("error", err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emulatedStdout.push(null);
|
||||||
|
emulatedStderr.push(null);
|
||||||
|
if (emulatedStdout._readableState && emulatedStdout._readableState.length > 0 && emulatedStdout._readableState.flowing !== null) {
|
||||||
|
emulatedStdout.on("end", function() {
|
||||||
|
eventEmitter.emit("exit", appStatus, null);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
eventEmitter.emit("exit", appStatus, null);
|
eventEmitter.emit("exit", appStatus, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var eventEmitter = new EventEmitter();
|
var eventEmitter = new EventEmitter();
|
||||||
var packetHeader = Buffer.alloc(8);
|
var packetHeader = Buffer.alloc(8);
|
||||||
|
@ -441,7 +455,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
||||||
stderr += data.toString();
|
stderr += data.toString();
|
||||||
});
|
});
|
||||||
req.pipe(handler.stdin);
|
req.pipe(handler.stdin);
|
||||||
handler.on("exit", (code, signal) => {
|
handler.on("exit", function (code, signal) {
|
||||||
if (!cned && (signal || code !== 0)) {
|
if (!cned && (signal || code !== 0)) {
|
||||||
var ex = new Error("Process execution failed!" + (stderr ? " Reason: " + stderr.trim() : ""));
|
var ex = new Error("Process execution failed!" + (stderr ? " Reason: " + stderr.trim() : ""));
|
||||||
if (!callServerError) {
|
if (!callServerError) {
|
||||||
|
|
Loading…
Reference in a new issue