forked from svrjs/svrjs
Add checks for zero-length head and foot in static file serving function
This commit is contained in:
parent
0a3371878c
commit
9c82164433
1 changed files with 15 additions and 11 deletions
16
svr.js
16
svr.js
|
@ -3728,17 +3728,17 @@ if (!cluster.isPrimary) {
|
||||||
try {
|
try {
|
||||||
if (ext == "html") {
|
if (ext == "html") {
|
||||||
function afterWriteCallback() {
|
function afterWriteCallback() {
|
||||||
|
if(foot.length > 0 && end > head.length + filelen) {
|
||||||
readStream.on("end", function () {
|
readStream.on("end", function () {
|
||||||
if(end > head.length + filelen) {
|
|
||||||
res.end(foot.substring(0, end - head.length - filelen + 1));
|
res.end(foot.substring(0, end - head.length - filelen + 1));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
readStream.pipe(res, {
|
readStream.pipe(res, {
|
||||||
end: (end > head.length + filelen) ? false : true
|
end: !(foot.length > 0 && end > head.length + filelen)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
res.writeHead(206, http.STATUS_CODES[206], hdhds);
|
res.writeHead(206, http.STATUS_CODES[206], hdhds);
|
||||||
if (begin > head.length) {
|
if (head.length == 0 || begin > head.length) {
|
||||||
afterWriteCallback();
|
afterWriteCallback();
|
||||||
} else if (!res.write(head.substring(begin, head.length - begin))) {
|
} else if (!res.write(head.substring(begin, head.length - begin))) {
|
||||||
res.on("drain", afterWriteCallback);
|
res.on("drain", afterWriteCallback);
|
||||||
|
@ -3869,15 +3869,19 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
if (ext == "html") {
|
if (ext == "html") {
|
||||||
function afterWriteCallback() {
|
function afterWriteCallback() {
|
||||||
|
if (foot.length > 0) {
|
||||||
readStream.on("end", function () {
|
readStream.on("end", function () {
|
||||||
resStream.end(foot);
|
resStream.end(foot);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
readStream.pipe(resStream, {
|
readStream.pipe(resStream, {
|
||||||
end: false
|
end: (foot.length == 0)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
res.writeHead(200, http.STATUS_CODES[200], hdhds);
|
res.writeHead(200, http.STATUS_CODES[200], hdhds);
|
||||||
if (!resStream.write(head)) {
|
if (head.length == 0) {
|
||||||
|
afterWriteCallback();
|
||||||
|
} else if (!resStream.write(head)) {
|
||||||
resStream.on("drain", afterWriteCallback);
|
resStream.on("drain", afterWriteCallback);
|
||||||
} else {
|
} else {
|
||||||
process.nextTick(afterWriteCallback);
|
process.nextTick(afterWriteCallback);
|
||||||
|
|
Reference in a new issue