diff --git a/client/plugos/proxy_fetch.ts b/client/plugos/proxy_fetch.ts index cb178657..01ee72e1 100644 --- a/client/plugos/proxy_fetch.ts +++ b/client/plugos/proxy_fetch.ts @@ -17,6 +17,7 @@ export type ProxyFetchResponse64 = { export type ProxyFetchRequest = { method?: string; headers?: Record; + responseEncoding?: string; body?: Uint8Array | string | any; }; diff --git a/client/plugos/syscalls/fetch.ts b/client/plugos/syscalls/fetch.ts index 1fd6fea5..d3d1785d 100644 --- a/client/plugos/syscalls/fetch.ts +++ b/client/plugos/syscalls/fetch.ts @@ -43,7 +43,8 @@ export function sandboxFetchSyscalls( ); // Do sensible things with the body based on the content type let body: any; - const contentTypeHeader = resp.headers.get("x-proxy-header-content-type"); + const contentTypeHeader = options.responseEncoding || + resp.headers.get("x-proxy-header-content-type"); const statusCode = +(resp.headers.get("x-proxy-status-code") || "200"); if (contentTypeHeader?.startsWith("application/json")) { body = await resp.json(); diff --git a/client/space_lua/stdlib/table.ts b/client/space_lua/stdlib/table.ts index d4bcf56b..029d54ae 100644 --- a/client/space_lua/stdlib/table.ts +++ b/client/space_lua/stdlib/table.ts @@ -147,14 +147,24 @@ export const tableApi = new LuaTable({ return tbl; }), unpack: new LuaBuiltinFunction( - (_sf, tbl: LuaTable, i?: number, j?: number) => { - i = i ?? 1; - j = j ?? tbl.length; - const result = []; - for (let k = i; k <= j; k++) { - result.push(tbl.get(k)); + (_sf, tbl: LuaTable | any[], i?: number, j?: number) => { + if (Array.isArray(tbl)) { + i = i ?? 1; + j = j ?? tbl.length; + const result = []; + for (let k = i; k <= j; k++) { + result.push(tbl[k - 1]); + } + return new LuaMultiRes(result); + } else { + i = i ?? 1; + j = j ?? tbl.length; + const result = []; + for (let k = i; k <= j; k++) { + result.push(tbl.get(k)); + } + return new LuaMultiRes(result); } - return new LuaMultiRes(result); }, ),