2024-02-09 04:00:45 +08:00
|
|
|
import type { SysCallMapping } from "../system.ts";
|
2024-03-16 22:29:24 +08:00
|
|
|
import { ProxyFetchRequest, ProxyFetchResponse } from "../../proxy_fetch.ts";
|
2024-02-09 04:00:45 +08:00
|
|
|
import { base64Encode } from "../../crypto.ts";
|
2023-08-05 00:56:55 +08:00
|
|
|
|
|
|
|
export function sandboxFetchSyscalls(): SysCallMapping {
|
|
|
|
return {
|
|
|
|
"sandboxFetch.fetch": async (
|
|
|
|
_ctx,
|
|
|
|
url: string,
|
|
|
|
options: ProxyFetchRequest,
|
|
|
|
): Promise<ProxyFetchResponse> => {
|
|
|
|
// console.log("Got sandbox fetch ", url);
|
|
|
|
const resp = await fetch(url, options);
|
|
|
|
return {
|
|
|
|
status: resp.status,
|
|
|
|
ok: resp.ok,
|
|
|
|
headers: Object.fromEntries(resp.headers.entries()),
|
|
|
|
base64Body: base64Encode(new Uint8Array(await resp.arrayBuffer())),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|