fix content-type and compression
This commit is contained in:
@@ -206,7 +206,7 @@ async function sendRawFile(socket, path) {
|
|||||||
const contypes = wtvmime.getContentType(path);
|
const contypes = wtvmime.getContentType(path);
|
||||||
let headers = "200 OK\n"
|
let headers = "200 OK\n"
|
||||||
headers += "Content-Type: " + contypes[0] + "\n";
|
headers += "Content-Type: " + contypes[0] + "\n";
|
||||||
headers += "wtv-modern-content-type" + contypes[1];
|
headers += "wtv-modern-content-type: " + contypes[1];
|
||||||
fs.readFile(path, null, function (err, data) {
|
fs.readFile(path, null, function (err, data) {
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
});
|
});
|
||||||
@@ -1415,7 +1415,7 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
const eol = "\n";
|
const eol = "\n";
|
||||||
let timezone = "-0000";
|
let timezone = "-0000";
|
||||||
let wtv_connection_close = false;
|
let wtv_connection_close = false;
|
||||||
|
console.log(headers_obj)
|
||||||
if (typeof (data) === 'undefined' || data === null) data = '';
|
if (typeof (data) === 'undefined' || data === null) data = '';
|
||||||
if (typeof (headers_obj) === 'string') {
|
if (typeof (headers_obj) === 'string') {
|
||||||
// string to header object
|
// string to header object
|
||||||
@@ -1476,6 +1476,7 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add last modified if not a dynamic script
|
// Add last modified if not a dynamic script
|
||||||
if (socket_sessions[socket.id]) {
|
if (socket_sessions[socket.id]) {
|
||||||
if (socket_sessions[socket.id].request_headers) {
|
if (socket_sessions[socket.id].request_headers) {
|
||||||
@@ -1525,6 +1526,7 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(compression_type)
|
||||||
|
|
||||||
// webtvism
|
// webtvism
|
||||||
if (headers_obj["minisrv-force-compression"]) {
|
if (headers_obj["minisrv-force-compression"]) {
|
||||||
@@ -1532,6 +1534,10 @@ async function sendToClient(socket, headers_obj, data = null) {
|
|||||||
delete headers_obj["minisrv-force-compression"];
|
delete headers_obj["minisrv-force-compression"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headers_obj["wtv-modern-content-type"]) {
|
||||||
|
delete headers_obj["wtv-modern-content-type"];
|
||||||
|
}
|
||||||
|
|
||||||
if (socket.res) { // pc mode with response object available
|
if (socket.res) { // pc mode with response object available
|
||||||
if (compression_type == 1) compression_type = 2; // wtv-lzpf not supported in pc mode
|
if (compression_type == 1) compression_type = 2; // wtv-lzpf not supported in pc mode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class WTVMime {
|
|||||||
let compression_type = 0; // no compression
|
let compression_type = 0; // no compression
|
||||||
if (ssid_session) {
|
if (ssid_session) {
|
||||||
if (ssid_session.capabilities) {
|
if (ssid_session.capabilities) {
|
||||||
if (ssid_session.capabilities['client-can-receive-compressed-data']) {
|
if (ssid_session.capabilities.get('client-can-receive-compressed-data')) {
|
||||||
|
|
||||||
if (this.minisrv_config.config.enable_lzpf_compression || this.minisrv_config.config.force_compression_type) {
|
if (this.minisrv_config.config.enable_lzpf_compression || this.minisrv_config.config.force_compression_type) {
|
||||||
compression_type = 1; // lzpf
|
compression_type = 1; // lzpf
|
||||||
@@ -61,7 +61,7 @@ class WTVMime {
|
|||||||
// should we bother to compress?
|
// should we bother to compress?
|
||||||
let content_type = "";
|
let content_type = "";
|
||||||
if (typeof (headers_obj) == 'string') content_type = headers_obj;
|
if (typeof (headers_obj) == 'string') content_type = headers_obj;
|
||||||
else content_type = (typeof (headers_obj["wtv-modern-content-type"]) != 'undefined') ? headers_obj["wtv-modern-content-type"] : headers_obj["Content-type"];
|
else content_type = (typeof (headers_obj["wtv-modern-content-type"]) !== 'undefined') ? headers_obj["wtv-modern-content-type"] : headers_obj["Content-type"];
|
||||||
|
|
||||||
if (content_type) {
|
if (content_type) {
|
||||||
// both lzpf and gzip
|
// both lzpf and gzip
|
||||||
@@ -100,7 +100,7 @@ class WTVMime {
|
|||||||
*/
|
*/
|
||||||
getContentType(path) {
|
getContentType(path) {
|
||||||
const file_ext = this.wtvshared.getFileExt(path).toLowerCase();
|
const file_ext = this.wtvshared.getFileExt(path).toLowerCase();
|
||||||
let wtv_mime_type, modern_mime_type = "";
|
let wtv_mime_type, modern_mime_type;
|
||||||
// process WebTV overrides, fall back to generic mime lookup
|
// process WebTV overrides, fall back to generic mime lookup
|
||||||
switch (file_ext) {
|
switch (file_ext) {
|
||||||
case "aif":
|
case "aif":
|
||||||
@@ -192,7 +192,7 @@ class WTVMime {
|
|||||||
|
|
||||||
modern_mime_type = this.mime.lookup(path);
|
modern_mime_type = this.mime.lookup(path);
|
||||||
if (modern_mime_type === false) modern_mime_type = "application/octet-stream";
|
if (modern_mime_type === false) modern_mime_type = "application/octet-stream";
|
||||||
if (wtv_mime_type == "") wtv_mime_type = modern_mime_type;
|
if (typeof wtv_mime_type === 'undefined') wtv_mime_type = modern_mime_type;
|
||||||
return new Array(wtv_mime_type, modern_mime_type);
|
return new Array(wtv_mime_type, modern_mime_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user