From 5cf95e22d9a93687519ae2dc610202d2f436f4c6 Mon Sep 17 00:00:00 2001 From: zefie Date: Thu, 30 May 2024 12:27:01 -0400 Subject: [PATCH] fix http proxy --- zefie_wtvp_minisrv/app.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index 6fc6c8bd..0f8b3a8e 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -927,13 +927,7 @@ function handleProxy(socket, request_type, request_headers, res, data) { res.headers['Content-Type'] = res.headers['content-type']; delete (res.headers['content-type']) } - - if (res.headers['Content-Type'].substr(0, 4) == "text" && request_type != "http" && request_type != "https") { - var data_t = data.toString().replaceAll("http://", request_type + "://").replaceAll("https://", request_type + "://"); - data = [Buffer.from(data_t)] - } - - + // header pass-through whitelist, case insensitive comparsion to server, however, you should // specify the header case as you intend for the client var headers = stripHeaders(res.headers, [ @@ -949,6 +943,14 @@ function handleProxy(socket, request_type, request_headers, res, data) { headers["wtv-http-proxy"] = true; headers["wtv-trusted"] = false; + if (res.headers['Content-Type'].substr(0, 4) == "text") { + if (request_type != "http" && request_type != "https") { + // replace http and https links on non http/https protocol (for proto:// for example) + var data_t = data.toString().replaceAll("http://", request_type + "://").replaceAll("https://", request_type + "://"); + data = [Buffer.from(data_t)] + } + } + // if Connection: close header, set our internal variable to close the socket if (headers['Connection']) { if (headers['Connection'].toLowerCase().indexOf('close') !== -1) { @@ -1036,8 +1038,6 @@ async function doHTTPProxy(socket, request_headers) { options.port = minisrv_config.services[request_type].external_proxy_port; options.path = request_headers.request.split(' ')[1]; options.headers.Host = request_data.host + ":" + request_data.port; - options.headers.Connection = 'close'; - options.insecureHTTPParser = true; if (minisrv_config.services[request_type].replace_protocol) { options.path = options.path.replace(request_type, minisrv_config.services[request_type].replace_protocol); }