1
0
Fork 0
forked from svrjs/svrjs

Update to SVR.JS 3.14.5

This commit is contained in:
Dorian Niemiec 2024-03-09 16:37:18 +01:00
parent d7b0fc463e
commit 0161b04e1f
4 changed files with 44 additions and 63 deletions

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>SVR.JS 3.14.4</title> <title>SVR.JS 3.14.5</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.4</h1> <h1>Welcome to SVR.JS 3.14.5</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/>
@ -85,10 +85,8 @@
</code> </code>
<p>Changes:</p> <p>Changes:</p>
<ul style="display: inline-block; margin: 0;"> <ul style="display: inline-block; margin: 0;">
<li>Updated <i>tar</i> and <i>graceful-fs</i> libraries.</li> <li>Fixed "www." URL redirect functionality.</li>
<li>Added support for URLs with double slashes.</li> <li>Improved HTTP/1.x API compatibility with HTTP/2.</li>
<li>Rewritten HTTP to HTTPS redirect functionality.</li>
<li>Changed default directory listing icons.</li>
</ul> </ul>
<p> <p>
<a href="/tests.html">Tests</a><br/> <a href="/tests.html">Tests</a><br/>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>SVR.JS 3.14.4 Licenses</title> <title>SVR.JS 3.14.5 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.4 Licenses</h1> <h1>SVR.JS 3.14.5 Licenses</h1>
<h2>SVR.JS 3.14.4</h2> <h2>SVR.JS 3.14.5</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.4</h2> <h2>Packages used by SVR.JS 3.14.5</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>

53
svr.js
View file

@ -69,7 +69,7 @@ function deleteFolderRecursive(path) {
} }
var os = require("os"); var os = require("os");
var version = "3.14.4"; var version = "3.14.5";
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
@ -1698,7 +1698,6 @@ function sha256(s) {
hash.update(s); hash.update(s);
return hash.digest("hex"); return hash.digest("hex");
} else { } else {
var chrsz = 8; var chrsz = 8;
var hexcase = 0; var hexcase = 0;
@ -2918,57 +2917,40 @@ if (!cluster.isPrimary) {
// Make HTTP/1.x API-based scripts compatible with HTTP/2.0 API // Make HTTP/1.x API-based scripts compatible with HTTP/2.0 API
if (configJSON.enableHTTP2 == true && req.httpVersion == "2.0") { if (configJSON.enableHTTP2 == true && req.httpVersion == "2.0") {
try {
// Set HTTP/1.x methods (to prevent process warnings) // Set HTTP/1.x methods (to prevent process warnings)
res.writeHeadNodeApi = res.writeHead; res.writeHeadNodeApi = res.writeHead;
res.setHeaderNodeApi = res.setHeader; res.setHeaderNodeApi = res.setHeader;
res.writeHead = function (a, b, c) { res.writeHead = function (a, b, c) {
var table = c; var table = c;
if (typeof (b) == "object") table = b; if (typeof (b) == "object") table = b;
if (table == undefined) table = this.tHeaders; if (table == undefined) table = this.tHeaders;
table = JSON.parse(JSON.stringify(table)); table = JSON.parse(JSON.stringify(table));
if (table["content-type"] != undefined && table["Content-Type"] != undefined) { Object.keys(table).forEach(function (key) {
delete table["content-type"]; var al = key.toLowerCase();
} if (al == "transfer-encoding" || al == "connection" || al == "keep-alive" || al == "upgrade") delete table[key];
delete table["transfer-encoding"]; });
delete table["connection"];
delete table["keep-alive"];
delete table["upgrade"];
if (res.stream && res.stream.destroyed) { if (res.stream && res.stream.destroyed) {
return false; return false;
} else { } else {
return res.writeHeadNodeApi(a, table); return res.writeHeadNodeApi(a, table);
} }
}; };
res.setHeader = function (headerName, headerValue) {
res.setHeader = function (a, b) { var al = headerName.toLowerCase();
if (a != "transfer-encoding" && a != "connection" && a != "keep-alive" && a != "upgrade") return res.setHeaderNodeApi(a, b); if (al != "transfer-encoding" && al != "connection" && al != "keep-alive" && al != "upgrade") return res.setHeaderNodeApi(headerName, headerValue);
return false; return false;
}; };
// Set HTTP/1.x headers // Set HTTP/1.x headers
if (!req.headers.host) req.headers.host = req.headers[":authority"]; if (!req.headers.host) req.headers.host = req.headers[":authority"];
(req.headers[":path"] == undefined ? (function () {})() : req.url = req.headers[":path"]); if (!req.url) req.url = req.headers[":path"];
req.protocol = req.headers[":scheme"]; if (!req.protocol) req.protocol = req.headers[":scheme"];
var headers = [":path", ":method"]; if (!req.method) req.method = req.headers[":method"];
for (var i = 0; i < headers.length; i++) { if (req.headers[":path"] == undefined || req.headers[":method"] == undefined) {
if (req.headers[headers[i]] == undefined) { var err = new Error("Either \":path\" or \":method\" pseudoheader is missing.");
var cheaders = getCustomHeaders(); if(Buffer.alloc) err.rawPacket = Buffer.alloc(0);
cheaders["Content-Type"] = "text/html; charset=utf-8"; reqerrhandler(err, req.socket, fromMain);
res.writeHead(400, "Bad Request", cheaders);
res.write("<html><head><title>400 Bad Request</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /></head><body><h1>400 Bad Request</h1><p>The request you sent is invalid. <p><i>" + (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + (req.headers[":authority"] == undefined ? "" : " on " + req.headers[":authority"]) + "</i></p></body></html>");
res.end();
return;
}
}
} catch (err) {
var cheaders = getCustomHeaders();
cheaders["Content-Type"] = "text/html; charset=utf-8";
cheaders[":status"] = "500";
res.stream.respond(cheaders);
res.stream.write("<html><head><title>500 Internal Server Error</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /></head><body><h1>500 Internal Server Error</h1><p>The server had an unexpected error. Below, error stack is shown: </p><code>" + (stackHidden ? "[error stack hidden]" : generateErrorStack(err)).replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>").replace(/\r/g, "<br/>").replace(/ {2}/g, "&nbsp;&nbsp;") + "</code><p>Please contact with developer/administrator of the website.</p><p><i>" + (exposeServerVersion ? "SVR.JS/" + version + " (" + getOS() + "; " + (process.isBun ? ("Bun/v" + process.versions.bun + "; like Node.JS/" + process.version) : ("Node.JS/" + process.version)) + ")" : "SVR.JS").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + (req.headers[":authority"] == undefined ? "" : " on " + req.headers[":authority"]) + "</i></p></body></html>");
res.stream.end();
return;
} }
} }
@ -4240,12 +4222,13 @@ if (!cluster.isPrimary) {
// Handle redirects to addresses with "www." prefix // Handle redirects to addresses with "www." prefix
if (wwwredirect) { if (wwwredirect) {
var hostname = req.headers.host.split[":"]; var hostname = req.headers.host.split(":");
var hostport = null; var hostport = null;
if (hostname.length > 1 && (hostname[0] != "[" || hostname[hostname.length - 1] != "]")) hostport = hostname.pop(); if (hostname.length > 1 && (hostname[0] != "[" || hostname[hostname.length - 1] != "]")) hostport = hostname.pop();
hostname = hostname.join(":"); hostname = hostname.join(":");
if (hostname == domain && hostname.indexOf("www.") != 0) { if (hostname == domain && hostname.indexOf("www.") != 0) {
redirect((req.socket.encrypted ? "https" : "http") + "://www." + hostname + (hostport ? ":" + hostport : "") + req.url.replace(/\/+/g, "/")); redirect((req.socket.encrypted ? "https" : "http") + "://www." + hostname + (hostport ? ":" + hostport : "") + req.url.replace(/\/+/g, "/"));
return;
} }
} }

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>SVR.JS 3.14.4 Tests</title> <title>SVR.JS 3.14.5 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.4 Tests</h1> <h1>SVR.JS 3.14.5 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>