From 0161b04e1f78493bed7d21cddc6ff0d9af5977d9 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 9 Mar 2024 16:37:18 +0100 Subject: [PATCH] Update to SVR.JS 3.14.5 --- index.html | 10 +++--- licenses/index.html | 8 ++--- svr.js | 85 ++++++++++++++++++--------------------------- tests.html | 4 +-- 4 files changed, 44 insertions(+), 63 deletions(-) diff --git a/index.html b/index.html index 17e38c0..288ba91 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - SVR.JS 3.14.4 + SVR.JS 3.14.5 -

Welcome to SVR.JS 3.14.4

+

Welcome to SVR.JS 3.14.5



@@ -85,10 +85,8 @@

Changes:

Tests
diff --git a/licenses/index.html b/licenses/index.html index d9ede85..fc74aab 100644 --- a/licenses/index.html +++ b/licenses/index.html @@ -1,7 +1,7 @@ - SVR.JS 3.14.4 Licenses + SVR.JS 3.14.5 Licenses -

SVR.JS 3.14.4 Licenses

-

SVR.JS 3.14.4

+

SVR.JS 3.14.5 Licenses

+

SVR.JS 3.14.5

MIT License

@@ -37,7 +37,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-

Packages used by SVR.JS 3.14.4

+

Packages used by SVR.JS 3.14.5

License: MIT
diff --git a/svr.js b/svr.js index d5db0e4..ba880ca 100644 --- a/svr.js +++ b/svr.js @@ -69,7 +69,7 @@ function deleteFolderRecursive(path) { } var os = require("os"); -var version = "3.14.4"; +var version = "3.14.5"; var singlethreaded = false; if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions @@ -1698,7 +1698,6 @@ function sha256(s) { hash.update(s); return hash.digest("hex"); } else { - var chrsz = 8; var hexcase = 0; @@ -2918,57 +2917,40 @@ if (!cluster.isPrimary) { // Make HTTP/1.x API-based scripts compatible with HTTP/2.0 API if (configJSON.enableHTTP2 == true && req.httpVersion == "2.0") { - try { - // Set HTTP/1.x methods (to prevent process warnings) - res.writeHeadNodeApi = res.writeHead; - res.setHeaderNodeApi = res.setHeader; - res.writeHead = function (a, b, c) { - var table = c; - if (typeof (b) == "object") table = b; - if (table == undefined) table = this.tHeaders; - table = JSON.parse(JSON.stringify(table)); - if (table["content-type"] != undefined && table["Content-Type"] != undefined) { - delete table["content-type"]; - } - delete table["transfer-encoding"]; - delete table["connection"]; - delete table["keep-alive"]; - delete table["upgrade"]; - if (res.stream && res.stream.destroyed) { - return false; - } else { - return res.writeHeadNodeApi(a, table); - } - }; + // Set HTTP/1.x methods (to prevent process warnings) + res.writeHeadNodeApi = res.writeHead; + res.setHeaderNodeApi = res.setHeader; - res.setHeader = function (a, b) { - if (a != "transfer-encoding" && a != "connection" && a != "keep-alive" && a != "upgrade") return res.setHeaderNodeApi(a, b); + res.writeHead = function (a, b, c) { + var table = c; + if (typeof (b) == "object") table = b; + if (table == undefined) table = this.tHeaders; + table = JSON.parse(JSON.stringify(table)); + Object.keys(table).forEach(function (key) { + var al = key.toLowerCase(); + if (al == "transfer-encoding" || al == "connection" || al == "keep-alive" || al == "upgrade") delete table[key]; + }); + if (res.stream && res.stream.destroyed) { return false; - }; - - // Set HTTP/1.x headers - if (!req.headers.host) req.headers.host = req.headers[":authority"]; - (req.headers[":path"] == undefined ? (function () {})() : req.url = req.headers[":path"]); - req.protocol = req.headers[":scheme"]; - var headers = [":path", ":method"]; - for (var i = 0; i < headers.length; i++) { - if (req.headers[headers[i]] == undefined) { - var cheaders = getCustomHeaders(); - cheaders["Content-Type"] = "text/html; charset=utf-8"; - res.writeHead(400, "Bad Request", cheaders); - res.write("400 Bad Request

400 Bad Request

The request you sent is invalid.

" + (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, "&").replace(//g, ">") + (req.headers[":authority"] == undefined ? "" : " on " + req.headers[":authority"]) + "

"); - res.end(); - return; - } + } else { + return res.writeHeadNodeApi(a, table); } - } catch (err) { - var cheaders = getCustomHeaders(); - cheaders["Content-Type"] = "text/html; charset=utf-8"; - cheaders[":status"] = "500"; - res.stream.respond(cheaders); - res.stream.write("500 Internal Server Error

500 Internal Server Error

The server had an unexpected error. Below, error stack is shown:

" + (stackHidden ? "[error stack hidden]" : generateErrorStack(err)).replace(/\r\n/g, "
").replace(/\n/g, "
").replace(/\r/g, "
").replace(/ {2}/g, "  ") + "

Please contact with developer/administrator of the website.

" + (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, "&").replace(//g, ">") + (req.headers[":authority"] == undefined ? "" : " on " + req.headers[":authority"]) + "

"); - res.stream.end(); - return; + }; + res.setHeader = function (headerName, headerValue) { + var al = headerName.toLowerCase(); + if (al != "transfer-encoding" && al != "connection" && al != "keep-alive" && al != "upgrade") return res.setHeaderNodeApi(headerName, headerValue); + return false; + }; + + // Set HTTP/1.x headers + if (!req.headers.host) req.headers.host = req.headers[":authority"]; + if (!req.url) req.url = req.headers[":path"]; + if (!req.protocol) req.protocol = req.headers[":scheme"]; + if (!req.method) req.method = req.headers[":method"]; + if (req.headers[":path"] == undefined || req.headers[":method"] == undefined) { + var err = new Error("Either \":path\" or \":method\" pseudoheader is missing."); + if(Buffer.alloc) err.rawPacket = Buffer.alloc(0); + reqerrhandler(err, req.socket, fromMain); } } @@ -4240,12 +4222,13 @@ if (!cluster.isPrimary) { // Handle redirects to addresses with "www." prefix if (wwwredirect) { - var hostname = req.headers.host.split[":"]; + var hostname = req.headers.host.split(":"); var hostport = null; if (hostname.length > 1 && (hostname[0] != "[" || hostname[hostname.length - 1] != "]")) hostport = hostname.pop(); hostname = hostname.join(":"); if (hostname == domain && hostname.indexOf("www.") != 0) { redirect((req.socket.encrypted ? "https" : "http") + "://www." + hostname + (hostport ? ":" + hostport : "") + req.url.replace(/\/+/g, "/")); + return; } } diff --git a/tests.html b/tests.html index a6a864c..3ef3565 100644 --- a/tests.html +++ b/tests.html @@ -1,7 +1,7 @@ - SVR.JS 3.14.4 Tests + SVR.JS 3.14.5 Tests -

SVR.JS 3.14.4 Tests

+

SVR.JS 3.14.5 Tests

Directory (without trailing slash)

Directory (with query)