chore: release SVR.JS 4.0.2

This commit is contained in:
Dorian Niemiec 2024-10-15 18:25:36 +02:00
parent 3bf8ff799e
commit f4fc6ba165
7 changed files with 45 additions and 34 deletions

View file

@ -1,6 +1,7 @@
const fs = require("fs");
const http = require("http");
const defaultPageCSS = require("../res/defaultPageCSS.js");
const statusCodes = require("../res/statusCodes.js");
const generateErrorStack = require("../utils/generateErrorStack.js");
const serverHTTPErrorDescs = require("../res/httpErrorDescriptions.js");
const generateServerString = require("../utils/generateServerString.js");
@ -265,14 +266,14 @@ function clientErrorHandler(err, socket) {
parseInt(process.version.split(".")[0].substring(1)) >= 16
) {
// Disable custom error page for HTTP SSL error
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
res.writeHead(errorCode, statusCodes[errorCode], cheaders);
res.write(
`<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}${"</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p><p><i>{server}</i></p></body></html>"
.replace(
/{errorMessage}/g,
errorCode.toString() +
" " +
http.STATUS_CODES[errorCode]
statusCodes[errorCode]
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
@ -316,7 +317,7 @@ function clientErrorHandler(err, socket) {
fs.readFile(errorFile, (err, data) => {
try {
if (err) throw err;
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
res.writeHead(errorCode, statusCodes[errorCode], cheaders);
responseEnd(
data
.toString()
@ -324,7 +325,7 @@ function clientErrorHandler(err, socket) {
/{errorMessage}/g,
errorCode.toString() +
" " +
http.STATUS_CODES[errorCode]
statusCodes[errorCode]
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
@ -378,7 +379,7 @@ function clientErrorHandler(err, socket) {
} else if (err.code == "ELOOP") {
additionalError = 508;
}
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
res.writeHead(errorCode, statusCodes[errorCode], cheaders);
res.write(
`<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p>${
additionalError == 404
@ -389,7 +390,7 @@ function clientErrorHandler(err, socket) {
/{errorMessage}/g,
errorCode.toString() +
" " +
http.STATUS_CODES[errorCode]
statusCodes[errorCode]
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")

View file

@ -1,4 +1,3 @@
const http = require("http");
const fs = require("fs");
const net = require("net");
const defaultPageCSS = require("../res/defaultPageCSS.js");
@ -10,6 +9,7 @@ const matchHostname = require("../utils/matchHostname.js");
const generateServerString = require("../utils/generateServerString.js");
const parseURL = require("../utils/urlParser.js");
const deepClone = require("../utils/deepClone.js");
const statusCodes = require("../res/statusCodes.js");
let serverconsole = {};
let middleware = [];
@ -134,7 +134,7 @@ function requestHandler(req, res) {
req.socket.remoteAddress == "localhost")
) {
let headers = config.getCustomHeaders();
res.writeHead(204, http.STATUS_CODES[204], headers);
res.writeHead(204, statusCodes[204], headers);
res.end();
return;
}
@ -173,9 +173,9 @@ function requestHandler(req, res) {
"Server responded with " + code.toString() + " code."
);
}
if (typeof codeDescription != "string" && http.STATUS_CODES[code]) {
if (typeof codeDescription != "string" && statusCodes[code]) {
if (!headers) headers = codeDescription;
codeDescription = http.STATUS_CODES[code];
codeDescription = statusCodes[code];
}
lastStatusCode = code;
}
@ -444,7 +444,7 @@ function requestHandler(req, res) {
fs.readFile(errorFile, (err, data) => {
try {
if (err) throw err;
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
res.writeHead(errorCode, statusCodes[errorCode], cheaders);
res.responseEnd(
data
.toString()
@ -452,7 +452,7 @@ function requestHandler(req, res) {
/{errorMessage}/g,
errorCode.toString() +
" " +
http.STATUS_CODES[errorCode]
statusCodes[errorCode]
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
@ -523,7 +523,7 @@ function requestHandler(req, res) {
additionalError = 508;
}
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
res.writeHead(errorCode, statusCodes[errorCode], cheaders);
res.write(
`<!DOCTYPE html><html><head><title>{errorMessage}</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}</style></head><body><h1>{errorMessage}</h1><p>{errorDesc}</p>${
additionalError == 404
@ -534,7 +534,7 @@ function requestHandler(req, res) {
/{errorMessage}/g,
errorCode.toString() +
" " +
http.STATUS_CODES[errorCode]
statusCodes[errorCode]
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
@ -620,7 +620,7 @@ function requestHandler(req, res) {
: 301;
// Write the response header with the appropriate status code and message
res.writeHead(statusCode, http.STATUS_CODES[statusCode], customHeaders);
res.writeHead(statusCode, statusCodes[statusCode], customHeaders);
// Log the redirection message
logFacilities.resmessage("Client redirected to " + destination);
@ -656,7 +656,7 @@ function requestHandler(req, res) {
// Respond with list of methods
let hdss = config.getCustomHeaders();
hdss["Allow"] = "GET, POST, HEAD, OPTIONS";
res.writeHead(204, http.STATUS_CODES[204], hdss);
res.writeHead(204, statusCodes[204], hdss);
res.end();
return;
} else {

View file

@ -1,5 +1,5 @@
const http = require("http");
const defaultPageCSS = require("../res/defaultPageCSS.js");
const statusCodes = require("../res/statusCodes.js");
const svrjsInfo = require("../../svrjs.json");
const { name } = svrjsInfo;
@ -7,7 +7,7 @@ module.exports = (req, res, logFacilities, config, next) => {
if (req.isProxy) {
let eheaders = config.getCustomHeaders();
eheaders["Content-Type"] = "text/html; charset=utf-8";
res.writeHead(501, http.STATUS_CODES[501], eheaders);
res.writeHead(501, statusCodes[501], eheaders);
res.write(
`<!DOCTYPE html><html><head><title>Proxy not implemented</title><meta name="viewport" content="width=device-width, initial-scale=1.0" /><style>${defaultPageCSS}</style></head><body><h1>Proxy not implemented</h1><p>${name
.replace(/&/g, "&amp;")
@ -34,7 +34,7 @@ module.exports = (req, res, logFacilities, config, next) => {
if (req.method == "OPTIONS") {
let hdss = config.getCustomHeaders();
hdss["Allow"] = "GET, POST, HEAD, OPTIONS";
res.writeHead(204, http.STATUS_CODES[204], hdss);
res.writeHead(204, statusCodes[204], hdss);
res.end();
return;
} else if (

View file

@ -1,4 +1,3 @@
const http = require("http");
const fs = require("fs");
const os = require("os");
const zlib = require("zlib");
@ -9,6 +8,7 @@ const ipMatch = require("../utils/ipMatch.js");
const createRegex = require("../utils/createRegex.js");
const sha256 = require("../utils/sha256.js");
const sizify = require("../utils/sizify.js");
const statusCodes = require("../res/statusCodes.js");
const svrjsInfo = require("../../svrjs.json");
const { name } = svrjsInfo;
@ -140,7 +140,7 @@ module.exports = (req, res, logFacilities, config, next) => {
// Check if the client's request matches the ETag value (If-None-Match)
const clientETag = req.headers["if-none-match"];
if (clientETag === fileETag) {
res.writeHead(304, http.STATUS_CODES[304], {
res.writeHead(304, statusCodes[304], {
ETag: clientETag
});
res.end();
@ -206,14 +206,14 @@ module.exports = (req, res, logFacilities, config, next) => {
begin < res.head.length &&
end - begin < res.head.length
) {
res.writeHead(206, http.STATUS_CODES[206], rhd);
res.writeHead(206, statusCodes[206], rhd);
res.end(res.head.substring(begin, end + 1));
return;
} else if (
ext == "html" &&
begin >= res.head.length + filelen
) {
res.writeHead(206, http.STATUS_CODES[206], rhd);
res.writeHead(206, statusCodes[206], rhd);
res.end(
res.foot.substring(
begin - res.head.length - filelen,
@ -278,7 +278,7 @@ module.exports = (req, res, logFacilities, config, next) => {
)
});
};
res.writeHead(206, http.STATUS_CODES[206], rhd);
res.writeHead(206, statusCodes[206], rhd);
if (res.head.length == 0 || begin > res.head.length) {
afterWriteCallback();
} else if (
@ -291,7 +291,7 @@ module.exports = (req, res, logFacilities, config, next) => {
process.nextTick(afterWriteCallback);
}
} else {
res.writeHead(206, http.STATUS_CODES[206], rhd);
res.writeHead(206, statusCodes[206], rhd);
readStream.pipe(res);
}
logFacilities.resmessage(
@ -302,7 +302,7 @@ module.exports = (req, res, logFacilities, config, next) => {
}
});
} else {
res.writeHead(206, http.STATUS_CODES[206], rhd);
res.writeHead(206, statusCodes[206], rhd);
res.end();
}
}
@ -461,7 +461,7 @@ module.exports = (req, res, logFacilities, config, next) => {
end: res.foot.length == 0
});
};
res.writeHead(200, http.STATUS_CODES[200], hdhds);
res.writeHead(200, statusCodes[200], hdhds);
if (res.head.length == 0) {
afterWriteCallback();
} else if (!resStream.write(res.head)) {
@ -470,7 +470,7 @@ module.exports = (req, res, logFacilities, config, next) => {
process.nextTick(afterWriteCallback);
}
} else {
res.writeHead(200, http.STATUS_CODES[200], hdhds);
res.writeHead(200, statusCodes[200], hdhds);
readStream.pipe(resStream);
}
logFacilities.resmessage(
@ -481,7 +481,7 @@ module.exports = (req, res, logFacilities, config, next) => {
}
});
} else {
res.writeHead(200, http.STATUS_CODES[200], hdhds);
res.writeHead(200, statusCodes[200], hdhds);
res.end();
logFacilities.resmessage("Client successfully received content.");
}
@ -890,7 +890,7 @@ module.exports = (req, res, logFacilities, config, next) => {
}
// Send the directory listing response
res.writeHead(200, http.STATUS_CODES[200], {
res.writeHead(200, statusCodes[200], {
"Content-Type": "text/html; charset=utf-8"
});
res.end(

View file

@ -1,7 +1,7 @@
const http = require("http");
const os = require("os");
const defaultPageCSS = require("../res/defaultPageCSS.js");
const sizify = require("../utils/sizify.js");
const statusCodes = require("../res/statusCodes.js");
const svrjsInfo = require("../../svrjs.json");
const { name } = svrjsInfo;
@ -57,7 +57,7 @@ module.exports = (req, res, logFacilities, config, next) => {
}%`;
statusBody += `<br/>Thread PID: ${process.pid}<br/>`;
res.writeHead(200, http.STATUS_CODES[200], {
res.writeHead(200, statusCodes[200], {
"Content-Type": "text/html; charset=utf-8"
});
res.end(

10
src/res/statusCodes.js Normal file
View file

@ -0,0 +1,10 @@
const http = require("http");
const statusCodes = {
...http.STATUS_CODES,
497: "HTTP Request Sent to HTTPS Port",
598: "Network Read Timeout Error",
599: "Network Connect Timeout Error"
};
module.exports = statusCodes;

View file

@ -1,9 +1,9 @@
{
"version": "4.0.1",
"version": "4.0.2",
"name": "SVR.JS",
"documentationURL": "https://svrjs.org/docs",
"statisticsServerCollectEndpoint": "https://statistics.svrjs.org/collect.svr",
"changes": [
"Fixed a bug with no request ID shown for multiline log entries for HTTP requests."
"Fixed a bug with 497, 598, and 599 status code HTTP responses."
]
}