1
0
Fork 0
forked from svrjs/svrjs

Pull from SVR.JS 3.7.1

This commit is contained in:
Dorian Niemiec 2023-08-21 19:32:31 +02:00
parent e6c1194086
commit 54ba71212b

22
svr.js
View file

@ -2067,7 +2067,7 @@ if (!cluster.isPrimary) {
return ph;
}
if (req.headers["x-svr-js-from-main-thread"] == "true" && (!req.socket.remoteAddress || req.socket.remoteAddress == "::1" || req.socket.remoteAddress == "::ffff:127.0.0.1" || req.socket.remoteAddress == "127.0.0.1" || req.socket.remoteAddress == "localhost")) {
if (req.headers["x-svr-js-from-main-thread"] == "true" && (!req.socket.remoteAddress || req.socket.remoteAddress == "::1" || req.socket.remoteAddress == "::ffff:127.0.0.1" || req.socket.remoteAddress == "127.0.0.1" || req.socket.remoteAddress == "localhost" || req.socket.remoteAddress == host || req.socket.remoteAddress == "::ffff:" + host)) {
var headers = getCustomHeaders();
res.writeHead(204, "No Content", headers);
res.end();
@ -2404,7 +2404,7 @@ if (!cluster.isPrimary) {
head += (headername + ": " + headerValueS);
});
} else {
if (headernames[i].match(/[^\x09\x20-\x7e\x80-\xff]|.:/) || headers[headername].match(/[^\x09\x20-\x7e\x80-\xff]/)) throw new Error("Invalid header!!! (" + headername + ")");
if (headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) || headers[headername].match(/[^\x09\x20-\x7e\x80-\xff]/)) throw new Error("Invalid header!!! (" + headername + ")");
head += (headername + ": " + headers[headername]);
}
head += "\r\n";
@ -2554,6 +2554,12 @@ if (!cluster.isPrimary) {
}
cheaders["Content-Type"] = "text/html; charset=utf-8";
if (errorCode == 405 && !cheaders["Allow"]) cheaders["Allow"] = "GET, POST, HEAD, OPTIONS";
if(err.code == "ERR_SSL_HTTP_REQUEST" && process.version && parseInt(process.version.split(".")[0].substr(1)) >= 16) {
//Disable custom error page for HTTP SSL error
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
res.write(("<html><head><title>{errorMessage}</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p><p><i>{server}</i></p></body></html>").replace(/{errorMessage}/g, errorCode.toString() + " " + http.STATUS_CODES[errorCode]).replace(/{errorDesc}/g, serverErrorDescs[errorCode]).replace(/{stack}/g, stack.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>").replace(/\r/g, "<br/>").replace(/ {2}/g, "&nbsp;&nbsp;")).replace(/{server}/g, "" + (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS") + (extName == undefined ? "" : " " + extName)).replace(/{contact}/g, serverAdmin.replace(/\./g, "[dot]").replace(/@/g, "[at]")));
res.end();
} else {
fs.readFile(errorFile, function (err, data) {
try {
if (err) throw err;
@ -2578,7 +2584,7 @@ if (!cluster.isPrimary) {
res.end();
}
});
}
}
}
var reqip = socket.remoteAddress;
@ -2882,7 +2888,7 @@ if (!cluster.isPrimary) {
function getCustomHeaders() {
var ph = JSON.parse(JSON.stringify(customHeaders));
Object.keys(ph).forEach(function (phk) {
if (typeof ph[phk] == "string") ph[phk] = ph[phk].replace(/\{path\}/g, req.url);
if (typeof ph[phk] == "string") ph[phk] = ph[phk].replace(/\{path\}/g, request.url);
});
return ph;
}
@ -2938,7 +2944,7 @@ if (!cluster.isPrimary) {
}
}
if (request.headers["x-svr-js-from-main-thread"] == "true" && (!request.socket.remoteAddress || request.socket.remoteAddress == "::1" || request.socket.remoteAddress == "::ffff:127.0.0.1" || request.socket.remoteAddress == "127.0.0.1" || request.socket.remoteAddress == "localhost")) {
if (request.headers["x-svr-js-from-main-thread"] == "true" && (!request.socket.remoteAddress || request.socket.remoteAddress == "::1" || request.socket.remoteAddress == "::ffff:127.0.0.1" || request.socket.remoteAddress == "127.0.0.1" || request.socket.remoteAddress == "localhost" || request.socket.remoteAddress == host || request.socket.remoteAddress == "::ffff:" + host)) {
var headers = getCustomHeaders();
response.writeHead(204, "No Content", headers);
response.end();
@ -5025,13 +5031,13 @@ function start(init) {
}
if (!cluster.isPrimary) {
pbkdf2CacheIntervalId = setInterval(function () {
pbkdf2Cache = pbkdf2Cache.every(function(entry) {
pbkdf2Cache = pbkdf2Cache.filter(function(entry) {
return entry.addDate > (new Date() - 3600000);
});
scryptCache = scryptCache.every(function(entry) {
scryptCache = scryptCache.filter(function(entry) {
return entry.addDate > (new Date() - 3600000);
});
}, 3600000);
}, 10000);
}
if (!cluster.isPrimary && cluster.isPrimary !== undefined) {
process.on("message", function (line) {