forked from svrjs/svrjs
Remove redundant fs.stat in static file serving function
This commit is contained in:
parent
e584cce286
commit
80943bf695
1 changed files with 179 additions and 208 deletions
31
svr.js
31
svr.js
|
@ -3799,36 +3799,8 @@ if (!cluster.isPrimary) {
|
||||||
if (!acceptEncoding) acceptEncoding = "";
|
if (!acceptEncoding) acceptEncoding = "";
|
||||||
|
|
||||||
// Check if the requested file exists and handle errors
|
// Check if the requested file exists and handle errors
|
||||||
fs.stat(readFrom, function (err, stats) {
|
|
||||||
if (err) {
|
|
||||||
if (err.code == "ENOENT") {
|
|
||||||
callServerError(404);
|
|
||||||
serverconsole.errmessage("Resource not found.");
|
|
||||||
} else if (err.code == "ENOTDIR") {
|
|
||||||
callServerError(404); // Assume that file doesn't exist.
|
|
||||||
serverconsole.errmessage("Resource not found.");
|
|
||||||
} else if (err.code == "EACCES") {
|
|
||||||
callServerError(403);
|
|
||||||
serverconsole.errmessage("Access denied.");
|
|
||||||
} else if (err.code == "ENAMETOOLONG") {
|
|
||||||
callServerError(414);
|
|
||||||
} else if (err.code == "EMFILE") {
|
|
||||||
callServerError(503);
|
|
||||||
} else if (err.code == "ELOOP") {
|
|
||||||
callServerError(508); // The symbolic link loop is detected during file system operations.
|
|
||||||
serverconsole.errmessage("Symbolic link loop detected.");
|
|
||||||
} else {
|
|
||||||
callServerError(500, err);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the requested resource is a file
|
// Check if the requested resource is a file
|
||||||
if (stats.isDirectory()) {
|
if (!stats.isFile()) {
|
||||||
callServerError(501);
|
|
||||||
serverconsole.errmessage("SVR.JS expected file but got directory instead.");
|
|
||||||
return;
|
|
||||||
} else if (!stats.isFile()) {
|
|
||||||
callServerError(501);
|
callServerError(501);
|
||||||
serverconsole.errmessage("SVR.JS doesn't support block devices, character devices, FIFOs nor sockets.");
|
serverconsole.errmessage("SVR.JS doesn't support block devices, character devices, FIFOs nor sockets.");
|
||||||
return;
|
return;
|
||||||
|
@ -4055,7 +4027,6 @@ if (!cluster.isPrimary) {
|
||||||
callServerError(500, err);
|
callServerError(500, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue