Merge branch 'lzpf-compression'

This commit is contained in:
zefie
2021-08-08 12:57:23 -04:00

View File

@@ -551,8 +551,10 @@ function headerStringToObj(headers, response = false) {
return headers_obj; return headers_obj;
} }
async function sendToClient(socket, headers_obj, data, compress_data = false) { async function sendToClient(socket, headers_obj, data) {
var compress_data = false;
var headers = ""; var headers = "";
var content_length = 0;
if (typeof (data) === 'undefined') data = ''; if (typeof (data) === 'undefined') data = '';
if (typeof (headers_obj) === 'string') { if (typeof (headers_obj) === 'string') {
// string to header object // string to header object
@@ -594,19 +596,16 @@ async function sendToClient(socket, headers_obj, data, compress_data = false) {
// compress if needed // compress if needed
if (compress_data && clen > 0) { if (compress_data && clen > 0) {
content_length = clen;
headers_obj["wtv-lzpf"] = 0; headers_obj["wtv-lzpf"] = 0;
var wtvcomp = new WTVLzpf(); var wtvcomp = new WTVLzpf();
data = wtvcomp.Compress(data); data = wtvcomp.Compress(data);
console.log("data", data)
wtvcomp = null; // Makes the garbage gods happy so it cleans up our mess wtvcomp = null; // Makes the garbage gods happy so it cleans up our mess
} }
if (headers_obj['minisrv-already-compressed']) delete headers_obj['minisrv-already-compressed'];
// encrypt if needed // encrypt if needed
if (socket_sessions[socket.id].secure == true) { if (socket_sessions[socket.id].secure == true) {
headers_obj["wtv-encrypted"] = 'true'; headers_obj["wtv-encrypted"] = 'true';
@@ -623,14 +622,16 @@ async function sendToClient(socket, headers_obj, data, compress_data = false) {
if (headers_obj["Content-Length"]) delete headers_obj["Content-Length"]; if (headers_obj["Content-Length"]) delete headers_obj["Content-Length"];
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. if (content_length == 0) {
// It matches the HTTP spec anyway so leaving. if (typeof data.length !== 'undefined') {
if (typeof data.length !== 'undefined') { content_length = data.length;
headers_obj["Content-length"] = data.length; } else if (typeof data.byteLength !== 'undefined') {
} else if (typeof data.byteLength !== 'undefined') { content_length = data.byteLength;
headers_obj["Content-length"] = data.byteLength; }
} }
headers_obj["Content-length"] = content_length;
if (ssid_sessions[socket.ssid]) { if (ssid_sessions[socket.ssid]) {
if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
if (ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64) { if (ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64) {