1
0
Fork 0
forked from svrjs/svrjs

Remove calls to getCustomHeaders in vres function

This commit is contained in:
Dorian Niemiec 2024-05-03 12:01:17 +02:00
parent 1226839163
commit befabe2c9a

27
svr.js
View file

@ -3511,9 +3511,9 @@ if (!cluster.isPrimary) {
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.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/>"; statusBody += "<br/>Thread PID: " + process.pid + "<br/>";
var hdhds = getCustomHeaders(); res.writeHead(200, http.STATUS_CODES[200], {
hdhds["Content-Type"] = "text/html; charset=utf-8"; "Content-Type": "text/html; charset=utf-8"
res.writeHead(200, http.STATUS_CODES[200], hdhds); });
res.end((head == "" ? "<html><head><title>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /></head><body>" : head.replace(/<head>/i, "<head><title>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</title>")) + "<h1>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</h1>" + statusBody + (foot == "" ? "</body></html>" : foot)); res.end((head == "" ? "<html><head><title>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /></head><body>" : head.replace(/<head>/i, "<head><title>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</title>")) + "<h1>SVR.JS status" + (req.headers.host == undefined ? "" : " for " + String(req.headers.host).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) + "</h1>" + statusBody + (foot == "" ? "</body></html>" : foot));
return; return;
} }
@ -3613,9 +3613,9 @@ if (!cluster.isPrimary) {
// Check if the client's request matches the ETag value (If-None-Match) // Check if the client's request matches the ETag value (If-None-Match)
var clientETag = req.headers["if-none-match"]; var clientETag = req.headers["if-none-match"];
if (clientETag === fileETag) { if (clientETag === fileETag) {
var headers = getCustomHeaders(); res.writeHead(304, http.STATUS_CODES[304], {
headers.ETag = clientETag; "ETag": clientETag
res.writeHead(304, http.STATUS_CODES[304], headers); });
res.end(); res.end();
return; return;
} }
@ -3623,9 +3623,9 @@ if (!cluster.isPrimary) {
// Check if the client's request doesn't match the ETag value (If-Match) // Check if the client's request doesn't match the ETag value (If-Match)
var ifMatchETag = req.headers["if-match"]; var ifMatchETag = req.headers["if-match"];
if (ifMatchETag && ifMatchETag !== "*" && ifMatchETag !== fileETag) { if (ifMatchETag && ifMatchETag !== "*" && ifMatchETag !== fileETag) {
var headers = getCustomHeaders(); callServerError(412, {
headers.ETag = clientETag; "ETag": clientETag;
callServerError(412, headers); });
return; return;
} }
} }
@ -3754,7 +3754,7 @@ if (!cluster.isPrimary) {
} }
try { try {
var hdhds = getCustomHeaders(); var hdhds = {};
if (useBrotli && isCompressable) { if (useBrotli && isCompressable) {
hdhds["Content-Encoding"] = "br"; hdhds["Content-Encoding"] = "br";
} else if (useDeflate && isCompressable) { } else if (useDeflate && isCompressable) {
@ -3846,10 +3846,6 @@ if (!cluster.isPrimary) {
} else if (stats.isDirectory()) { } else if (stats.isDirectory()) {
// Check if directory listing is enabled in the configuration // Check if directory listing is enabled in the configuration
if (checkForEnabledDirectoryListing(req.headers.host, req.socket ? req.socket.localAddress : undefined)) { if (checkForEnabledDirectoryListing(req.headers.host, req.socket ? req.socket.localAddress : undefined)) {
var customHeaders = getCustomHeaders();
customHeaders["Content-Type"] = "text/html; charset=utf-8";
res.writeHead(200, http.STATUS_CODES[200], customHeaders);
var customDirListingHeader = ""; var customDirListingHeader = "";
var customDirListingFooter = ""; var customDirListingFooter = "";
@ -4073,6 +4069,9 @@ if (!cluster.isPrimary) {
} }
// Send the directory listing response // Send the directory listing response
res.writeHead(200, http.STATUS_CODES[200], {
"Content-Type": "text/html; charset=utf-8"
});
res.end(htmlHead + directoryListingRows.join("") + htmlFoot); res.end(htmlHead + directoryListingRows.join("") + htmlFoot);
serverconsole.resmessage("Client successfully received content."); serverconsole.resmessage("Client successfully received content.");
}); });