diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index 41c27b60..e682e1b3 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -497,6 +497,7 @@ function headerStringToObj(headers, response = false) { async function sendToClient(socket, headers_obj, data) { var headers = ""; + var content_length = 0; if (typeof (data) === 'undefined') data = ''; if (typeof (headers_obj) === 'string') { // string to header object @@ -538,6 +539,8 @@ async function sendToClient(socket, headers_obj, data) { // compress if needed if (compress_data && clen > 0) { + content_length = clen; + headers_obj["wtv-lzpf"] = 0; var wtvcomp = new WTVLzpf(); @@ -562,14 +565,16 @@ async function sendToClient(socket, headers_obj, data) { if (headers_obj["Content-Length"]) delete headers_obj["Content-Length"]; if (headers_obj["Content-length"]) delete headers_obj["Content-length"]; - // On the WNI server this is the length before compression but we're using the length after compression. - // It matches the HTTP spec anyway so leaving. - if (typeof data.length !== 'undefined') { - headers_obj["Content-length"] = data.length; - } else if (typeof data.byteLength !== 'undefined') { - headers_obj["Content-length"] = data.byteLength; + if (content_length == 0) { + if (typeof data.length !== 'undefined') { + content_length = data.length; + } else if (typeof data.byteLength !== 'undefined') { + content_length = data.byteLength; + } } + headers_obj["Content-length"] = content_length; + if (ssid_sessions[socket.ssid]) { if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { if (ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64) {