From 16b7b91cfb38908f054a2c14bff9dbbfa38e1836 Mon Sep 17 00:00:00 2001 From: zefie Date: Fri, 21 Jan 2022 11:19:55 -0500 Subject: [PATCH] update comments and formatting --- zefie_wtvp_minisrv/WTVMime.js | 7 ++----- zefie_wtvp_minisrv/app.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/zefie_wtvp_minisrv/WTVMime.js b/zefie_wtvp_minisrv/WTVMime.js index b552de9a..4b4a0e2c 100644 --- a/zefie_wtvp_minisrv/WTVMime.js +++ b/zefie_wtvp_minisrv/WTVMime.js @@ -24,7 +24,6 @@ class WTVMime { } } - shouldWeCompress(ssid_session, headers_obj) { var compress_data = false; var compression_type = 0; // no compression @@ -74,11 +73,9 @@ class WTVMime { else if (content_type == "application/json") compress_data = true; if (compression_type == 2) { // gzip only - if (content_type.match(/^audio\/(x-)?(s3m|mod|xm)$/)) compress_data = true; // s3m, mod, xm - if (content_type.match(/^audio\/(x-)?(midi|wav|wave|aif(f)?)$/)) compress_data = true; // midi & wav + if (content_type.match(/^audio\/(x-)?(s3m|mod|xm|midi|wav|wave|aif(f)?))$/)) compress_data = true; // s3m, mod, xm, midi & wav if (content_type.match(/^application\/karaoke$/)) compress_data = true; // midi karaoke - if (content_type.match(/^binary\/x-wtv-approm$/)) compress_data = true; // approms - if (content_type.match(/^binary\/doom-data$/)) compress_data = true; // DOOM WADs + if (content_type.match(/^binary\/(x-wtv-approm|doom-data)/)) compress_data = true; // approms and DOOM WADs if (content_type.match(/^wtv\/download-list$/)) compress_data = true; // WebTV Download List } } diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index c8d06003..0b9fae31 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -379,7 +379,6 @@ async function processURL(socket, request_headers) { // check security if (!ssid_sessions[socket.ssid].isAuthorized(shortURL)) { // lockdown mode and URL not authorized - //socket_sessions[socket.id].close_me = true; headers = "300 Unauthorized\n"; headers += "Location: " + minisrv_config.config.unauthorized_url + "\n"; data = ""; @@ -393,11 +392,11 @@ async function processURL(socket, request_headers) { ssid_sessions[socket.ssid].lockdown = true; } - - if (shortURL.indexOf(':/') >= 0 && shortURL.indexOf('://') < 0) { + // Check URL for :/, but not :// (to differentiate wtv urls) + if (shortURL.indexOf(':/') >= 0 && shortURL.indexOf('://') == -1) { var ssid = socket.ssid; if (ssid == null) { - // prevent possible injection attacks via SSID and filesystem SessionStore + // prevent possible injection attacks via malformed SSID and filesystem SessionStore ssid = wtvshared.makeSafeSSID(request_headers["wtv-client-serial-number"]); if (ssid == "") ssid = null; } @@ -466,6 +465,7 @@ async function doHTTPProxy(socket, request_headers) { } } + // RFC7239 if (socket.remoteAddress != "127.0.0.1") { options.headers["X-Forwarded-For"] = socket.remoteAddress; } @@ -476,10 +476,13 @@ async function doHTTPProxy(socket, request_headers) { } if (minisrv_config.services[request_type].use_external_proxy && minisrv_config.services[request_type].external_proxy_port) { + // configure connection to an external proxy if (minisrv_config.services[request_type].external_proxy_is_socks) { + // configure connection to remote socks proxy var ProxyAgent = require('proxy-agent'); options.agent = new ProxyAgent("socks://" + (minisrv_config.services[request_type].external_proxy_host || "127.0.0.1") + ":" + minisrv_config.services[request_type].external_proxy_port); } else { + // configure connection to remote http proxy var proxy_agent = http; options.host = minisrv_config.services[request_type].external_proxy_host; options.port = minisrv_config.services[request_type].external_proxy_port; @@ -535,12 +538,16 @@ async function doHTTPProxy(socket, request_headers) { 'Last-Modified' ]); headers["wtv-http-proxy"] = true; + + // if Connection: close header, set our internal variable to close the socket if (headers['Connection']) { if (headers['Connection'].toLowerCase().indexOf('close') !== -1) { headers["wtv-connection-close"] = true; } } + // if a wtv-explaination is defined for an error code (except 200), define the header here to + // show the 'Explain' button on the client error ShowAlert if (minisrv_config.services['http']['wtv-explanation']) { if (minisrv_config.services['http']['wtv-explanation'][res.statusCode]) { headers['wtv-explanation-url'] = minisrv_config.services['http']['wtv-explanation'][res.statusCode]; @@ -612,7 +619,6 @@ function headerStringToObj(headers, response = false) { headers_obj_pre.forEach(function (d) { if (/^SECURE ON/.test(d) && !response) { headers_obj.secure = true; - //socket_sessions[socket.id].secure_headers = true; } else if (/^([0-9]{3}) $/.test(d.substring(0, 4)) && response) { headers_obj.http_response = d.replace("\r", ""); } else if (/^(GET |PUT |POST)$/.test(d.substring(0, 4)) && !response) {