forked from svrjs/svrjs
Update to SVR.JS 3.14.15
This commit is contained in:
parent
5e031fe997
commit
2ae73966ec
4 changed files with 71 additions and 63 deletions
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SVR.JS 3.14.14</title>
|
<title>SVR.JS 3.14.15</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome to SVR.JS 3.14.14</h1>
|
<h1>Welcome to SVR.JS 3.14.15</h1>
|
||||||
<br/>
|
<br/>
|
||||||
<img src="/logo.png" style="width: 256px; max-width: 100%;" />
|
<img src="/logo.png" style="width: 256px; max-width: 100%;" />
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -84,8 +84,8 @@
|
||||||
</code>
|
</code>
|
||||||
<p>Changes:</p>
|
<p>Changes:</p>
|
||||||
<ul style="display: inline-block; margin: 0;">
|
<ul style="display: inline-block; margin: 0;">
|
||||||
<li><i>console.log</i> and <i>stdout</i> are now disabled, when <i>stdout</i> is not a TTY (for example in situation when SVR.JS is running as a daemon), in order to improve performance.</li>
|
<li>Fixed crashes related to the request ID generation.</li>
|
||||||
<li>Errors that occurred, while adding SNI context to a server are now ignored.</li>
|
<li>Optimized HTTP compression functionality.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<a href="/tests.html">Tests</a><br/>
|
<a href="/tests.html">Tests</a><br/>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SVR.JS 3.14.14 Licenses</title>
|
<title>SVR.JS 3.14.15 Licenses</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -12,8 +12,8 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>SVR.JS 3.14.14 Licenses</h1>
|
<h1>SVR.JS 3.14.15 Licenses</h1>
|
||||||
<h2>SVR.JS 3.14.14</h2>
|
<h2>SVR.JS 3.14.15</h2>
|
||||||
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
||||||
MIT License<br/>
|
MIT License<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br/>
|
||||||
SOFTWARE.<br/>
|
SOFTWARE.<br/>
|
||||||
</div>
|
</div>
|
||||||
<h2>Packages used by SVR.JS 3.14.14</h2>
|
<h2>Packages used by SVR.JS 3.14.15</h2>
|
||||||
<div style="width: 100%; max-width: 1280px; margin: auto">
|
<div style="width: 100%; max-width: 1280px; margin: auto">
|
||||||
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
|
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
|
||||||
<div style="float: right;">License: MIT</div>
|
<div style="float: right;">License: MIT</div>
|
||||||
|
|
104
svr.js
104
svr.js
|
@ -69,7 +69,7 @@ function deleteFolderRecursive(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var os = require("os");
|
var os = require("os");
|
||||||
var version = "3.14.14";
|
var version = "3.14.15";
|
||||||
var singlethreaded = false;
|
var singlethreaded = false;
|
||||||
|
|
||||||
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
||||||
|
@ -2032,7 +2032,8 @@ if (!cluster.isPrimary) {
|
||||||
});
|
});
|
||||||
if (!disableToHTTPSRedirect) {
|
if (!disableToHTTPSRedirect) {
|
||||||
server2.on("connect", function (request, socket) {
|
server2.on("connect", function (request, socket) {
|
||||||
var reqIdInt = Math.round(Math.random() * 16777216);
|
var reqIdInt = Math.floor(Math.random() * 16777216);
|
||||||
|
if (reqIdInt == 16777216) reqIdInt = 0;
|
||||||
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
||||||
var serverconsole = {
|
var serverconsole = {
|
||||||
climessage: function (msg) {
|
climessage: function (msg) {
|
||||||
|
@ -2327,7 +2328,8 @@ if (!cluster.isPrimary) {
|
||||||
res.write(head);
|
res.write(head);
|
||||||
};
|
};
|
||||||
|
|
||||||
var reqIdInt = Math.round(Math.random() * 16777216);
|
var reqIdInt = Math.floor(Math.random() * 16777216);
|
||||||
|
if (reqIdInt == 16777216) reqIdInt = 0;
|
||||||
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
||||||
var serverconsole = {
|
var serverconsole = {
|
||||||
climessage: function (msg) {
|
climessage: function (msg) {
|
||||||
|
@ -2679,7 +2681,8 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function connhandler(request, socket, head) {
|
function connhandler(request, socket, head) {
|
||||||
var reqIdInt = Math.round(Math.random() * 16777216);
|
var reqIdInt = Math.floor(Math.random() * 16777216);
|
||||||
|
if (reqIdInt == 16777216) reqIdInt = 0;
|
||||||
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
||||||
var serverconsole = {
|
var serverconsole = {
|
||||||
climessage: function (msg) {
|
climessage: function (msg) {
|
||||||
|
@ -2798,7 +2801,8 @@ if (!cluster.isPrimary) {
|
||||||
|
|
||||||
function reqhandler(req, res, fromMain) {
|
function reqhandler(req, res, fromMain) {
|
||||||
if (fromMain === undefined) fromMain = true;
|
if (fromMain === undefined) fromMain = true;
|
||||||
var reqIdInt = Math.round(Math.random() * 16777216);
|
var reqIdInt = Math.floor(Math.random() * 16777216);
|
||||||
|
if (reqIdInt == 16777216) reqIdInt = 0;
|
||||||
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16);
|
||||||
var serverconsole = {
|
var serverconsole = {
|
||||||
climessage: function (msg) {
|
climessage: function (msg) {
|
||||||
|
@ -3626,39 +3630,6 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to check if compression is allowed for the file
|
|
||||||
function canCompress(path, list) {
|
|
||||||
var canCompress = true;
|
|
||||||
for (var i = 0; i < list.length; i++) {
|
|
||||||
if (createRegex(list[i], true).test(path)) {
|
|
||||||
canCompress = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return canCompress;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isCompressable = true;
|
|
||||||
try {
|
|
||||||
// Check for files not to compressed and compression enabling setting. Also check for browser quirks and adjust compression accordingly
|
|
||||||
if(configJSON.enableCompression !== true || !canCompress(href, dontCompress)) {
|
|
||||||
isCompressable = false; // Compression is disabled
|
|
||||||
} else if (ext != "html" && ext != "htm" && ext != "xhtml" && ext != "xht" && ext != "shtml") {
|
|
||||||
if (/^Mozilla\/4\.[0-9]+(( *\[[^)]*\] *| *)\([^)\]]*\))? *$/.test(req.headers["user-agent"]) && !(/https?:\/\/|[bB][oO][tT]|[sS][pP][iI][dD][eE][rR]|[sS][uU][rR][vV][eE][yY]|MSIE/.test(req.headers["user-agent"]))) {
|
|
||||||
isCompressable = false; // Netscape 4.x doesn't handle compressed data properly outside of HTML documents.
|
|
||||||
} else if (/^w3m\/[^ ]*$/.test(req.headers["user-agent"])) {
|
|
||||||
isCompressable = false; // w3m doesn't handle compressed data properly outside of HTML documents.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (/^Mozilla\/4\.0[6-8](( *\[[^)]*\] *| *)\([^)\]]*\))? *$/.test(req.headers["user-agent"]) && !(/https?:\/\/|[bB][oO][tT]|[sS][pP][iI][dD][eE][rR]|[sS][uU][rR][vV][eE][yY]|MSIE/.test(req.headers["user-agent"]))) {
|
|
||||||
isCompressable = false; // Netscape 4.06-4.08 doesn't handle compressed data properly.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
callServerError(500, err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle partial content request
|
// Handle partial content request
|
||||||
if (ext != "html" && req.headers["range"]) {
|
if (ext != "html" && req.headers["range"]) {
|
||||||
try {
|
try {
|
||||||
|
@ -3736,22 +3707,59 @@ if (!cluster.isPrimary) {
|
||||||
callServerError(500, err);
|
callServerError(500, err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Helper function to check if compression is allowed for the file
|
||||||
|
function canCompress(path, list) {
|
||||||
|
var canCompress = true;
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
if (createRegex(list[i], true).test(path)) {
|
||||||
|
canCompress = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canCompress;
|
||||||
|
}
|
||||||
|
|
||||||
|
var useBrotli = (ext != "br" && filelen > 256 && zlib.createBrotliCompress && acceptEncoding.match(/\bbr\b/));
|
||||||
|
var useDeflate = (ext != "zip" && filelen > 256 && acceptEncoding.match(/\bdeflate\b/));
|
||||||
|
var useGzip = (ext != "gz" && filelen > 256 && acceptEncoding.match(/\bgzip\b/));
|
||||||
|
|
||||||
|
var isCompressable = true;
|
||||||
try {
|
try {
|
||||||
var hdhds = getCustomHeaders();
|
// Check for files not to compressed and compression enabling setting. Also check for browser quirks and adjust compression accordingly
|
||||||
var brNotImplementedBun = false;
|
if((!useBrotli && !useDeflate && !useGzip) || configJSON.enableCompression !== true || !canCompress(href, dontCompress)) {
|
||||||
|
isCompressable = false; // Compression is disabled
|
||||||
|
} else if (ext != "html" && ext != "htm" && ext != "xhtml" && ext != "xht" && ext != "shtml") {
|
||||||
|
if (/^Mozilla\/4\.[0-9]+(( *\[[^)]*\] *| *)\([^)\]]*\))? *$/.test(req.headers["user-agent"]) && !(/https?:\/\/|[bB][oO][tT]|[sS][pP][iI][dD][eE][rR]|[sS][uU][rR][vV][eE][yY]|MSIE/.test(req.headers["user-agent"]))) {
|
||||||
|
isCompressable = false; // Netscape 4.x doesn't handle compressed data properly outside of HTML documents.
|
||||||
|
} else if (/^w3m\/[^ ]*$/.test(req.headers["user-agent"])) {
|
||||||
|
isCompressable = false; // w3m doesn't handle compressed data properly outside of HTML documents.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (/^Mozilla\/4\.0[6-8](( *\[[^)]*\] *| *)\([^)\]]*\))? *$/.test(req.headers["user-agent"]) && !(/https?:\/\/|[bB][oO][tT]|[sS][pP][iI][dD][eE][rR]|[sS][uU][rR][vV][eE][yY]|MSIE/.test(req.headers["user-agent"]))) {
|
||||||
|
isCompressable = false; // Netscape 4.06-4.08 doesn't handle compressed data properly.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
callServerError(500, err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Bun 1.1 has definition for zlib.createBrotliCompress, but throws an error while invoking the function.
|
// Bun 1.1 has definition for zlib.createBrotliCompress, but throws an error while invoking the function.
|
||||||
if (process.isBun && configJSON.enableCompression === true) {
|
if (process.isBun && useBrotli && isCompressable) {
|
||||||
try {
|
try {
|
||||||
zlib.createBrotliCompress();
|
zlib.createBrotliCompress();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
brNotImplementedBun = true;
|
useBrotli = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (configJSON.enableCompression === true && ext != "br" && filelen > 256 && isCompressable && !brNotImplementedBun && zlib.createBrotliCompress && acceptEncoding.match(/\bbr\b/)) {
|
|
||||||
|
try {
|
||||||
|
var hdhds = getCustomHeaders();
|
||||||
|
if (useBrotli && isCompressable) {
|
||||||
hdhds["Content-Encoding"] = "br";
|
hdhds["Content-Encoding"] = "br";
|
||||||
} else if (configJSON.enableCompression === true && ext != "zip" && filelen > 256 && isCompressable && acceptEncoding.match(/\bdeflate\b/)) {
|
} else if (useDeflate && isCompressable) {
|
||||||
hdhds["Content-Encoding"] = "deflate";
|
hdhds["Content-Encoding"] = "deflate";
|
||||||
} else if (configJSON.enableCompression === true && ext != "gz" && filelen > 256 && isCompressable && acceptEncoding.match(/\bgzip\b/)) {
|
} else if (useGzip && isCompressable) {
|
||||||
hdhds["Content-Encoding"] = "gzip";
|
hdhds["Content-Encoding"] = "gzip";
|
||||||
} else {
|
} else {
|
||||||
if (ext == "html") {
|
if (ext == "html") {
|
||||||
|
@ -3790,13 +3798,13 @@ if (!cluster.isPrimary) {
|
||||||
}).on("open", function () {
|
}).on("open", function () {
|
||||||
try {
|
try {
|
||||||
var resStream = {};
|
var resStream = {};
|
||||||
if (ext != "br" && filelen > 256 && isCompressable && !brNotImplementedBun && zlib.createBrotliCompress && acceptEncoding.match(/\bbr\b/)) {
|
if (useBrotli && isCompressable) {
|
||||||
resStream = zlib.createBrotliCompress();
|
resStream = zlib.createBrotliCompress();
|
||||||
resStream.pipe(res);
|
resStream.pipe(res);
|
||||||
} else if (ext != "zip" && filelen > 256 && isCompressable && acceptEncoding.match(/\bdeflate\b/)) {
|
} else if (useDeflate && isCompressable) {
|
||||||
resStream = zlib.createDeflateRaw();
|
resStream = zlib.createDeflateRaw();
|
||||||
resStream.pipe(res);
|
resStream.pipe(res);
|
||||||
} else if (ext != "gz" && filelen > 256 && isCompressable && acceptEncoding.match(/\bgzip\b/)) {
|
} else if (useGzip && isCompressable) {
|
||||||
resStream = zlib.createGzip();
|
resStream = zlib.createGzip();
|
||||||
resStream.pipe(res);
|
resStream.pipe(res);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>SVR.JS 3.14.14 Tests</title>
|
<title>SVR.JS 3.14.15 Tests</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>SVR.JS 3.14.14 Tests</h1>
|
<h1>SVR.JS 3.14.15 Tests</h1>
|
||||||
<h2>Directory (without trailing slash)</h2>
|
<h2>Directory (without trailing slash)</h2>
|
||||||
<iframe src="/testdir" width="50%" height="300px"></iframe>
|
<iframe src="/testdir" width="50%" height="300px"></iframe>
|
||||||
<h2>Directory (with query)</h2>
|
<h2>Directory (with query)</h2>
|
||||||
|
|
Reference in a new issue