1
0
Fork 0
forked from svrjs/svrjs

Remove redundant fs.stat in static file serving function

This commit is contained in:
Dorian Niemiec 2024-04-07 09:19:45 +02:00
parent e584cce286
commit 80943bf695

31
svr.js
View file

@ -3799,36 +3799,8 @@ if (!cluster.isPrimary) {
if (!acceptEncoding) acceptEncoding = "";
// 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
if (stats.isDirectory()) {
callServerError(501);
serverconsole.errmessage("SVR.JS expected file but got directory instead.");
return;
} else if (!stats.isFile()) {
if (!stats.isFile()) {
callServerError(501);
serverconsole.errmessage("SVR.JS doesn't support block devices, character devices, FIFOs nor sockets.");
return;
@ -4055,7 +4027,6 @@ if (!cluster.isPrimary) {
callServerError(500, err);
}
}
});
}
}
});