forked from svrjs/svrjs
Clean up the code.
This commit is contained in:
parent
88e923ffbc
commit
d85dedea65
1 changed files with 40 additions and 40 deletions
38
svr.js
38
svr.js
|
@ -1355,7 +1355,7 @@ if (secure) {
|
|||
var sniNames = Object.keys(sni);
|
||||
var sniCredentials = [];
|
||||
sniNames.forEach(function (sniName) {
|
||||
if(typeof sniName === "string" && sniName.match(/\*[^*.:]*\*[^*.:]*(?:\.|:|$)/)) {
|
||||
if (typeof sniName === "string" && sniName.match(/\*[^*.:]*\*[^*.:]*(?:\.|:|$)/)) {
|
||||
sniReDos = true;
|
||||
}
|
||||
sniCredentials.push({
|
||||
|
@ -1384,7 +1384,7 @@ function LOG(s) {
|
|||
flags: "a",
|
||||
autoClose: false
|
||||
});
|
||||
logFile.on("error", function(err) {
|
||||
logFile.on("error", function (err) {
|
||||
if (!s.match(/^SERVER WARNING MESSAGE(?: \[Request Id: [0-9a-f]{6}\])?: There was a problem while saving logs! Logs will not be kept in log file\. Reason: /) && !reallyExiting) serverconsole.locwarnmessage("There was a problem while saving logs! Logs will not be kept in log file. Reason: " + err.message);
|
||||
});
|
||||
}
|
||||
|
@ -2196,9 +2196,9 @@ if (!cluster.isPrimary) {
|
|||
});
|
||||
try {
|
||||
var snMatches = sniCredentialsSingle.name.match(/^([^:[]*|\[[^]]*\]?)((?::.*)?)$/);
|
||||
if(!snMatches[1][0].match(/^\.+$/)) snMatches[1][0] = snMatches[1][0].replace(/\.+$/,"");
|
||||
server._contexts[server._contexts.length-1][0] = new RegExp("^" + snMatches[1].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.:]*") + ((snMatches[1][0] == "[" || snMatches[1].match(/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/)) ? "" : "\.?") + snMatches[2].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "$", "i");
|
||||
} catch(ex) {
|
||||
if (!snMatches[1][0].match(/^\.+$/)) snMatches[1][0] = snMatches[1][0].replace(/\.+$/, "");
|
||||
server._contexts[server._contexts.length - 1][0] = new RegExp("^" + snMatches[1].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.:]*") + ((snMatches[1][0] == "[" || snMatches[1].match(/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/)) ? "" : "\.?") + snMatches[2].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "$", "i");
|
||||
} catch (ex) {
|
||||
// Can't replace regex, ignoring...
|
||||
}
|
||||
});
|
||||
|
@ -2304,8 +2304,8 @@ if (!cluster.isPrimary) {
|
|||
});
|
||||
};
|
||||
res.writeHead = function (code, name, headers) {
|
||||
if(code >= 400 && code <= 499) err4xxcounter++;
|
||||
if(code >= 500 && code <= 599) err5xxcounter++;
|
||||
if (code >= 400 && code <= 499) err4xxcounter++;
|
||||
if (code >= 500 && code <= 599) err5xxcounter++;
|
||||
var head = ("HTTP/1.1 " + code.toString() + " " + name + "\r\n");
|
||||
var headers = JSON.parse(JSON.stringify(headers));
|
||||
headers["Date"] = (new Date()).toGMTString();
|
||||
|
@ -3053,7 +3053,7 @@ if (!cluster.isPrimary) {
|
|||
var oldHostHeader = req.headers.host;
|
||||
if (typeof req.headers.host == "string") {
|
||||
req.headers.host = req.headers.host.toLowerCase();
|
||||
if(!req.headers.host.match(/^\.+$/)) req.headers.host = req.headers.host.replace(/\.$/g,"");
|
||||
if (!req.headers.host.match(/^\.+$/)) req.headers.host = req.headers.host.replace(/\.$/g, "");
|
||||
}
|
||||
|
||||
if (!isProxy) serverconsole.reqmessage("Client " + ((!reqip || reqip == "") ? "[unknown client]" : (reqip + ((reqport && reqport !== 0) && reqport != "" ? ":" + reqport : ""))) + " wants " + (req.method == "GET" ? "content in " : (req.method == "POST" ? "to post content in " : (req.method == "PUT" ? "to add content in " : (req.method == "DELETE" ? "to delete content in " : (req.method == "PATCH" ? "to patch content in " : "to access content using " + req.method + " method in "))))) + (req.headers.host == undefined ? "" : req.headers.host) + req.url);
|
||||
|
@ -3494,8 +3494,8 @@ if (!cluster.isPrimary) {
|
|||
statusBody += "Server errors (5xx): " + err5xxcounter + "<br/>";
|
||||
statusBody += "Average error rate: " + (Math.round(((err4xxcounter + err5xxcounter) / reqcounter) * 10000) / 100) + "%<br/>";
|
||||
statusBody += "Malformed HTTP requests: " + malformedcounter;
|
||||
if(process.memoryUsage) statusBody += "<br/>Memory usage of thread: " + sizify(process.memoryUsage().rss, true) + "B";
|
||||
if(process.cpuUsage) statusBody += "<br/>Total CPU usage by thread: u" + (process.cpuUsage().user / 1000) + "ms s" + (process.cpuUsage().system / 1000) + "ms - " + (Math.round((((process.cpuUsage().user + process.cpuUsage().system) / 1000000) / process.uptime()) * 1000) / 1000) + "%";
|
||||
if (process.memoryUsage) statusBody += "<br/>Memory usage of thread: " + sizify(process.memoryUsage().rss, true) + "B";
|
||||
if (process.cpuUsage) statusBody += "<br/>Total CPU usage by thread: u" + (process.cpuUsage().user / 1000) + "ms s" + (process.cpuUsage().system / 1000) + "ms - " + (Math.round((((process.cpuUsage().user + process.cpuUsage().system) / 1000000) / process.uptime()) * 1000) / 1000) + "%";
|
||||
statusBody += "<br/>Thread PID: " + process.pid + "<br/>";
|
||||
|
||||
var hdhds = getCustomHeaders();
|
||||
|
@ -4281,14 +4281,14 @@ if (!cluster.isPrimary) {
|
|||
if (!isProxy) {
|
||||
for (var i = (_mapBegIndex ? _mapBegIndex : 0); i < map.length; i++) {
|
||||
var mapEntry = map[i];
|
||||
if(href != "/" && (mapEntry.isNotDirectory || mapEntry.isNotFile) && !_fileState) {
|
||||
fs.stat("." + decodeURIComponent(href), function(err, stats) {
|
||||
if (href != "/" && (mapEntry.isNotDirectory || mapEntry.isNotFile) && !_fileState) {
|
||||
fs.stat("." + decodeURIComponent(href), function (err, stats) {
|
||||
var _fileState = 3;
|
||||
if(err) {
|
||||
if (err) {
|
||||
_fileState = 3;
|
||||
} else if(stats.isDirectory()) {
|
||||
} else if (stats.isDirectory()) {
|
||||
_fileState = 2;
|
||||
} else if(stats.isFile()) {
|
||||
} else if (stats.isFile()) {
|
||||
_fileState = 1;
|
||||
} else {
|
||||
_fileState = 3;
|
||||
|
@ -4312,7 +4312,7 @@ if (!cluster.isPrimary) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if(doCallback) callback(null, rewrittenURL);
|
||||
if (doCallback) callback(null, rewrittenURL);
|
||||
}
|
||||
|
||||
// Trailing slash redirection
|
||||
|
@ -4347,12 +4347,12 @@ if (!cluster.isPrimary) {
|
|||
var origHref = href;
|
||||
|
||||
// Add web root postfixes
|
||||
if(!isProxy) {
|
||||
if (!isProxy) {
|
||||
var urlWithPostfix = req.url;
|
||||
var postfixPrefix = "";
|
||||
wwwrootPostfixPrefixesVHost.every(function (currentPostfixPrefix) {
|
||||
if (req.url.indexOf(currentPostfixPrefix) == 0) {
|
||||
if (currentPostfixPrefix.match(/\/+$/)) postfixPrefix = currentPostfixPrefix.replace(/\/+$/,"");
|
||||
if (currentPostfixPrefix.match(/\/+$/)) postfixPrefix = currentPostfixPrefix.replace(/\/+$/, "");
|
||||
else if (urlWithPostfix.length == currentPostfixPrefix.length || urlWithPostfix[currentPostfixPrefix.length] == "?" || urlWithPostfix[currentPostfixPrefix.length] == "/" || urlWithPostfix[currentPostfixPrefix.length] == "#") postfixPrefix = currentPostfixPrefix;
|
||||
else return true;
|
||||
urlWithPostfix = urlWithPostfix.substr(postfixPrefix.length);
|
||||
|
@ -4425,7 +4425,7 @@ if (!cluster.isPrimary) {
|
|||
}
|
||||
|
||||
// Rewrite URLs
|
||||
rewriteURL(req.url, rewriteMap, function(err, rewrittenURL) {
|
||||
rewriteURL(req.url, rewriteMap, function (err, rewrittenURL) {
|
||||
if (err) {
|
||||
callServerError(500, undefined, err);
|
||||
return;
|
||||
|
|
Reference in a new issue