Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanburns committed Jul 26, 2023
1 parent 0c0f87c commit 1958382
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions bindings/wasm/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func (out *outputBinding) Init(ctx context.Context, metadata bindings.Metadata)
return fmt.Errorf("wasm: error instantiating host wasi functions: %w", err)
}
if _, found := imports[modeWasiHTTP]; found {
if out.meta.StrictSandbox {
return fmt.Errorf("can not instantiate wasi-http with strict sandbox")
}
err = wasi_http.Instantiate(ctx, out.runtime)
}
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions bindings/wasm/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
urlArgsFile = "file://testdata/args/main.wasm"
urlExampleFile = "file://testdata/example/main.wasm"
urlLoopFile = "file://testdata/loop/main.wasm"
urlHttpFile = "file://testdata/http/main.wasm"
urlHTTPFile = "file://testdata/http/main.wasm"
)

func Test_outputBinding_Init(t *testing.T) {
Expand Down Expand Up @@ -187,11 +187,11 @@ type handler struct{}

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/unknown" {
w.WriteHeader(404)
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("Not found"))
return
}
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
w.Write([]byte(r.URL.Path))
}

Expand All @@ -211,7 +211,7 @@ func Test_InvokeHttp(t *testing.T) {
tests := []testCase{
{
name: "http",
url: urlHttpFile,
url: urlHTTPFile,
request: &bindings.InvokeRequest{
Operation: ExecuteOperation,
},
Expand All @@ -220,7 +220,7 @@ func Test_InvokeHttp(t *testing.T) {
},
{
name: "unknown",
url: urlHttpFile,
url: urlHTTPFile,
request: &bindings.InvokeRequest{
Operation: ExecuteOperation,
},
Expand Down
4 changes: 4 additions & 0 deletions bindings/wasm/testdata/http/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default: main.wasm

main.wasm: main.go
tinygo build -target wasi -o main.wasm main.go
Binary file modified bindings/wasm/testdata/http/main.wasm
100644 → 100755
Binary file not shown.

0 comments on commit 1958382

Please sign in to comment.