update comments and formatting

This commit is contained in:
zefie
2022-01-21 11:19:55 -05:00
parent e9ede65602
commit 16b7b91cfb
2 changed files with 13 additions and 10 deletions

View File

@@ -24,7 +24,6 @@ class WTVMime {
} }
} }
shouldWeCompress(ssid_session, headers_obj) { shouldWeCompress(ssid_session, headers_obj) {
var compress_data = false; var compress_data = false;
var compression_type = 0; // no compression var compression_type = 0; // no compression
@@ -74,11 +73,9 @@ class WTVMime {
else if (content_type == "application/json") compress_data = true; else if (content_type == "application/json") compress_data = true;
if (compression_type == 2) { if (compression_type == 2) {
// gzip only // gzip only
if (content_type.match(/^audio\/(x-)?(s3m|mod|xm)$/)) compress_data = true; // s3m, mod, xm 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(/^audio\/(x-)?(midi|wav|wave|aif(f)?)$/)) compress_data = true; // midi & wav
if (content_type.match(/^application\/karaoke$/)) compress_data = true; // midi karaoke 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\/(x-wtv-approm|doom-data)/)) compress_data = true; // approms and DOOM WADs
if (content_type.match(/^binary\/doom-data$/)) compress_data = true; // DOOM WADs
if (content_type.match(/^wtv\/download-list$/)) compress_data = true; // WebTV Download List if (content_type.match(/^wtv\/download-list$/)) compress_data = true; // WebTV Download List
} }
} }

View File

@@ -379,7 +379,6 @@ async function processURL(socket, request_headers) {
// check security // check security
if (!ssid_sessions[socket.ssid].isAuthorized(shortURL)) { if (!ssid_sessions[socket.ssid].isAuthorized(shortURL)) {
// lockdown mode and URL not authorized // lockdown mode and URL not authorized
//socket_sessions[socket.id].close_me = true;
headers = "300 Unauthorized\n"; headers = "300 Unauthorized\n";
headers += "Location: " + minisrv_config.config.unauthorized_url + "\n"; headers += "Location: " + minisrv_config.config.unauthorized_url + "\n";
data = ""; data = "";
@@ -393,11 +392,11 @@ async function processURL(socket, request_headers) {
ssid_sessions[socket.ssid].lockdown = true; ssid_sessions[socket.ssid].lockdown = true;
} }
// Check URL for :/, but not :// (to differentiate wtv urls)
if (shortURL.indexOf(':/') >= 0 && shortURL.indexOf('://') < 0) { if (shortURL.indexOf(':/') >= 0 && shortURL.indexOf('://') == -1) {
var ssid = socket.ssid; var ssid = socket.ssid;
if (ssid == null) { 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"]); ssid = wtvshared.makeSafeSSID(request_headers["wtv-client-serial-number"]);
if (ssid == "") ssid = null; if (ssid == "") ssid = null;
} }
@@ -466,6 +465,7 @@ async function doHTTPProxy(socket, request_headers) {
} }
} }
// RFC7239
if (socket.remoteAddress != "127.0.0.1") { if (socket.remoteAddress != "127.0.0.1") {
options.headers["X-Forwarded-For"] = socket.remoteAddress; 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) { 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) { if (minisrv_config.services[request_type].external_proxy_is_socks) {
// configure connection to remote socks proxy
var ProxyAgent = require('proxy-agent'); 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); 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 { } else {
// configure connection to remote http proxy
var proxy_agent = http; var proxy_agent = http;
options.host = minisrv_config.services[request_type].external_proxy_host; options.host = minisrv_config.services[request_type].external_proxy_host;
options.port = minisrv_config.services[request_type].external_proxy_port; options.port = minisrv_config.services[request_type].external_proxy_port;
@@ -535,12 +538,16 @@ async function doHTTPProxy(socket, request_headers) {
'Last-Modified' 'Last-Modified'
]); ]);
headers["wtv-http-proxy"] = true; headers["wtv-http-proxy"] = true;
// if Connection: close header, set our internal variable to close the socket
if (headers['Connection']) { if (headers['Connection']) {
if (headers['Connection'].toLowerCase().indexOf('close') !== -1) { if (headers['Connection'].toLowerCase().indexOf('close') !== -1) {
headers["wtv-connection-close"] = true; 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']) {
if (minisrv_config.services['http']['wtv-explanation'][res.statusCode]) { if (minisrv_config.services['http']['wtv-explanation'][res.statusCode]) {
headers['wtv-explanation-url'] = 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) { headers_obj_pre.forEach(function (d) {
if (/^SECURE ON/.test(d) && !response) { if (/^SECURE ON/.test(d) && !response) {
headers_obj.secure = true; headers_obj.secure = true;
//socket_sessions[socket.id].secure_headers = true;
} else if (/^([0-9]{3}) $/.test(d.substring(0, 4)) && response) { } else if (/^([0-9]{3}) $/.test(d.substring(0, 4)) && response) {
headers_obj.http_response = d.replace("\r", ""); headers_obj.http_response = d.replace("\r", "");
} else if (/^(GET |PUT |POST)$/.test(d.substring(0, 4)) && !response) { } else if (/^(GET |PUT |POST)$/.test(d.substring(0, 4)) && !response) {