diff --git a/svr.js b/svr.js index 0dda952..2c6eea7 100644 --- a/svr.js +++ b/svr.js @@ -3241,12 +3241,13 @@ if (!cluster.isPrimary) { } try { - head = fs.existsSync("./.head") ? fs.readFileSync("./.head").toString() : (fs.existsSync("./head.html") ? fs.readFileSync("./head.html").toString() : ""); // header - foot = fs.existsSync("./.foot") ? fs.readFileSync("./.foot").toString() : (fs.existsSync("./foot.html") ? fs.readFileSync("./foot.html").toString() : ""); // footer + //head = fs.existsSync("./.head") ? fs.readFileSync("./.head").toString() : (fs.existsSync("./head.html") ? fs.readFileSync("./head.html").toString() : ""); // header + //foot = fs.existsSync("./.foot") ? fs.readFileSync("./.foot").toString() : (fs.existsSync("./foot.html") ? fs.readFileSync("./foot.html").toString() : ""); // footer } catch (err) { callServerError(500, err); } + // Function to perform HTTP redirection to a specified destination URL function redirect(destination, isTemporary, keepMethod, customHeaders) { // If keepMethod is a object, then save it to customHeaders @@ -3382,8 +3383,9 @@ if (!cluster.isPrimary) { var uobject = parseURL(req.url); var search = uobject.search; var href = uobject.pathname; - var ext = path.extname(href).toLowerCase(); - ext = ext.substring(1, ext.length + 1); + var ext = href.match(/[^\/]\.([^.]+)$/); + if(!ext) ext = ""; + else ext = ext[1].toLowerCase(); var decodedHref = ""; try { decodedHref = decodeURIComponent(href); @@ -3394,6 +3396,7 @@ if (!cluster.isPrimary) { return; } + if (req.headers["expect"] && req.headers["expect"] != "100-continue") { // Expectations not met. callServerError(417); @@ -3515,15 +3518,15 @@ if (!cluster.isPrimary) { return; } - var pth = decodeURIComponent(href).replace(/\/+/g, "/").substring(1); - var readFrom = "./" + pth; + var dHref = decodeURIComponent(href); + var readFrom = "." + dHref; var dirImagesMissing = false; fs.stat(readFrom, function (err, stats) { if (err) { if (err.code == "ENOENT") { - if (__dirname != process.cwd() && pth.match(/^\.dirimages\/(?:(?!\.png$).)+\.png$/)) { + if (__dirname != process.cwd() && dHref.match(/^\/\.dirimages\/(?:(?!\.png$).)+\.png$/)) { dirImagesMissing = true; - readFrom = __dirname + "/" + pth; + readFrom = __dirname + dHref; } else { callServerError(404); serverconsole.errmessage("Resource not found."); @@ -3564,25 +3567,22 @@ if (!cluster.isPrimary) { properDirectoryListingAndStaticFileServe(); } else { stats = s; - pth = (pth + "/index.xhtml").replace(/\/+/g, "/"); ext = "xhtml"; - readFrom = "./" + pth; + readFrom = (readFrom + "/index.xhtml").replace(/\/+/g, "/"); properDirectoryListingAndStaticFileServe(); } }); } else { stats = s; - pth = (pth + "/index.htm").replace(/\/+/g, "/"); ext = "htm"; - readFrom = "./" + pth; + readFrom = (readFrom + "/index.htm").replace(/\/+/g, "/"); properDirectoryListingAndStaticFileServe(); } }); } else { stats = s; - pth = (pth + "/index.html").replace(/\/+/g, "/"); ext = "html"; - readFrom = "./" + pth; + readFrom = (readFrom + "/index.html").replace(/\/+/g, "/"); properDirectoryListingAndStaticFileServe(); } }); @@ -3854,11 +3854,11 @@ if (!cluster.isPrimary) { var customDirListingFooter = ""; function getCustomDirListingHeader(callback) { - fs.readFile(("." + decodeURIComponent(href) + "/.dirhead").replace(/\/+/g, "/"), function (err, data) { + fs.readFile(("." + dHref + "/.dirhead").replace(/\/+/g, "/"), function (err, data) { if (err) { if (err.code == "ENOENT" || err.code == "EISDIR") { if (os.platform != "win32" || href != "/") { - fs.readFile(("." + decodeURIComponent(href) + "/HEAD.html").replace(/\/+/g, "/"), function (err, data) { + fs.readFile(("." + dHref + "/HEAD.html").replace(/\/+/g, "/"), function (err, data) { if (err) { if (err.code == "ENOENT" || err.code == "EISDIR") { callback(); @@ -3884,11 +3884,11 @@ if (!cluster.isPrimary) { } function getCustomDirListingFooter(callback) { - fs.readFile(("." + decodeURIComponent(href) + "/.dirfoot").replace(/\/+/g, "/"), function (err, data) { + fs.readFile(("." + dHref + "/.dirfoot").replace(/\/+/g, "/"), function (err, data) { if (err) { if (err.code == "ENOENT" || err.code == "EISDIR") { if (os.platform != "win32" || href != "/") { - fs.readFile(("." + decodeURIComponent(href) + "/FOOT.html").replace(/\/+/g, "/"), function (err, data) { + fs.readFile(("." + dHref + "/FOOT.html").replace(/\/+/g, "/"), function (err, data) { if (err) { if (err.code == "ENOENT" || err.code == "EISDIR") { callback(); @@ -3934,7 +3934,7 @@ if (!cluster.isPrimary) { htmlFoot = "