Fixes shell/fetch regression

This commit is contained in:
Zef Hemel
2023-07-24 09:36:33 +02:00
parent 7cd88eca14
commit 804c688a46
5 changed files with 29 additions and 14 deletions
+5 -5
View File
@@ -1,13 +1,13 @@
import type { SysCallMapping } from "../../plugos/system.ts";
import type { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts";
import {
performLocalFetch,
ProxyFetchRequest,
ProxyFetchResponse,
} from "../../common/proxy_fetch.ts";
import type { Client } from "../client.ts";
export function sandboxFetchSyscalls(
httpSpacePrimitives?: HttpSpacePrimitives,
client: Client,
): SysCallMapping {
return {
"sandboxFetch.fetch": async (
@@ -16,12 +16,12 @@ export function sandboxFetchSyscalls(
options: ProxyFetchRequest,
): Promise<ProxyFetchResponse> => {
// console.log("Got sandbox fetch ", url);
if (!httpSpacePrimitives) {
if (!client.remoteSpacePrimitives) {
// No SB server to proxy the fetch available so let's execute the request directly
return performLocalFetch(url, options);
}
const resp = httpSpacePrimitives.authenticatedFetch(
`${httpSpacePrimitives.url}/.rpc`,
const resp = client.remoteSpacePrimitives.authenticatedFetch(
`${client.remoteSpacePrimitives.url}/.rpc`,
{
method: "POST",
body: JSON.stringify({
+5 -5
View File
@@ -1,8 +1,8 @@
import { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts";
import { SysCallMapping } from "../../plugos/system.ts";
import type { Client } from "../client.ts";
export function shellSyscalls(
httpSpacePrimitives?: HttpSpacePrimitives,
client: Client,
): SysCallMapping {
return {
"shell.run": async (
@@ -10,11 +10,11 @@ export function shellSyscalls(
cmd: string,
args: string[],
): Promise<{ stdout: string; stderr: string; code: number }> => {
if (!httpSpacePrimitives) {
if (!client.remoteSpacePrimitives) {
throw new Error("Not supported in fully local mode");
}
const resp = httpSpacePrimitives.authenticatedFetch(
`${httpSpacePrimitives.url}/.rpc`,
const resp = client.remoteSpacePrimitives.authenticatedFetch(
`${client.remoteSpacePrimitives.url}/.rpc`,
{
method: "POST",
body: JSON.stringify({