update header handling

This commit is contained in:
zefie
2025-08-11 18:24:10 -04:00
parent e4aac5933e
commit 51565b56a6
4 changed files with 23 additions and 14 deletions

View File

@@ -1619,7 +1619,7 @@ async function sendToClient(socket, headers_obj, data = null) {
headers_obj = wtvshared.moveObjectKey("Connection", 1, headers_obj); // move Connection to second
headers_obj = wtvshared.moveObjectKey("Content-type", -1, headers_obj); // move Content-type to last
headers_obj = wtvshared.moveObjectKey("Content-length", "Content-type", headers_obj); // move Content-length to before Content-type
// remove x-powered-by header if client is WebTV
let xpower = wtvshared.getCaseInsensitiveKey("x-powered-by", headers_obj);
if (!xpower && socket.service_name) {
@@ -1657,6 +1657,11 @@ async function sendToClient(socket, headers_obj, data = null) {
if (k == "Status") {
headers += headers_obj[k] + eol;
} else {
if (typeof headers_obj[k] === 'object') {
headers_obj[k].forEach(function (v) {
headers += k + ": " + v + eol;
});
}
if (k.indexOf('_') >= 0) {
let j = k.split('_')[0];
headers += j + ": " + headers_obj[k] + eol;

View File

@@ -601,7 +601,7 @@ class WebTVClientSimulator {
request += `wtv-system-cpuspeed: 166187148\r\n`;
request += `wtv-system-sysconfig: 4163328\r\n`;
request += `wtv-disk-size: 8006\r\n`;
request += `wtv-viewer: zefie-minisrv-client_emu\r\n`; // Note: no space after colon
request += `wtv-viewer: zefie-minisrv-client-sim\r\n`; // Note: no space after colon
// Add content if POST
if (data) {

View File

@@ -12,7 +12,9 @@ if (session_data.getSessionData("address_book") != null) {
data = ``
for (let i = 0; i < address_book.length; i++) {
data += address_book[i].name + '\0' + address_book[i].address + '\0'
};
};
} else {
session_data.setSessionData("address_book", [])
}
// TODO: Why does the address book have a blank/corrupt entry when empty?

View File

@@ -475,15 +475,18 @@ class WTVShared {
} else if (d.indexOf(":") > 0) {
const d_split = d.split(':');
let header_name = d_split[0];
if (headers_obj[header_name] != null) {
header_name = header_name + "_" + inc_headers;
inc_headers++;
}
d_split.shift();
d = d_split.join(':');
headers_obj[header_name] = (d).trim("\r");
if (headers_obj[header_name].startsWith(" ")) {
headers_obj[header_name] = headers_obj[header_name].slice(1);
if (typeof headers_obj[header_name] === 'string') {
headers_obj[header_name] = [headers_obj[header_name]];
headers_obj[header_name].push((d_split.slice(1).join(':')).trim("\r"));
} else if (typeof headers_obj[header_name] === 'object') {
headers_obj[header_name].push((d_split.slice(1).join(':')).trim("\r"));
} else {
d_split.shift();
d = d_split.join(':');
headers_obj[header_name] = (d).trim("\r");
if (headers_obj[header_name].startsWith(" ")) {
headers_obj[header_name] = headers_obj[header_name].slice(1);
}
}
}
});
@@ -1443,8 +1446,7 @@ class WTVShared {
findObjectKeyIndex(key, obj, case_insensitive = false) {
const keys = Object.keys(obj);
if (case_insensitive) {
key = key.toLowerCase();
return keys.findIndex(k => k.toLowerCase() === key);
return keys.findIndex(k => k.toLowerCase() === key.toLowerCase());
}
return keys.indexOf(key);
}