Use uncompressed length for Content-length like WNI (fixes HTML pages)

This commit is contained in:
Eric MacDonald
2021-08-07 19:46:15 -04:00
parent 1bc7cadac5
commit 72dcce0f8f

View File

@@ -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,13 +565,15 @@ 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 (content_length == 0) {
if (typeof data.length !== 'undefined') {
headers_obj["Content-length"] = data.length;
content_length = data.length;
} else if (typeof data.byteLength !== 'undefined') {
headers_obj["Content-length"] = data.byteLength;
content_length = data.byteLength;
}
}
headers_obj["Content-length"] = content_length;
if (ssid_sessions[socket.ssid]) {
if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {