Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion tests/component/test_linker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from wasmtime import Engine, WasmtimeError, Module, Store
from wasmtime import Engine, WasiConfig, WasmtimeError, Module, Store
from wasmtime.component import Linker, Component, LinkerInstance


Expand Down Expand Up @@ -143,6 +143,34 @@ def test_shadow_func(self):
with linker.root() as l:
l.add_func('x', lambda: None)

def test_add_wasi_http(self):
engine = Engine()
linker = Linker(engine)
linker.add_wasip2()
linker.add_wasi_http()

with linker.root():
with self.assertRaises(WasmtimeError):
linker.add_wasi_http()

linker.close()

with Linker(engine) as l2:
l2.add_wasip2()
l2.add_wasi_http()
with self.assertRaises(WasmtimeError):
l2.add_wasi_http()
l2.allow_shadowing = True
l2.add_wasi_http()

def test_set_wasi_http(self):
engine = Engine()
store = Store(engine)
wasi = WasiConfig()
wasi.inherit_stdout()
store.set_wasi(wasi)
store.set_wasi_http()

def test_define_unknown_imports_as_traps(self):
engine = Engine()
store = Store(engine)
Expand Down
9 changes: 9 additions & 0 deletions wasmtime/_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def set_wasi(self, wasi: "WasiConfig") -> None:
if error:
raise WasmtimeError._from_ptr(error)

def set_wasi_http(self) -> None:
"""
Initializes the WASI HTTP context for this store.

Must be called before instantiating a component that uses `wasi:http`.
Requires WASI to be configured first via `set_wasi()`.
"""
ffi.wasmtime_context_set_wasi_http(self._context())

def set_epoch_deadline(self, ticks_after_current: int) -> None:
"""
Configures the relative epoch deadline, after the current engine's
Expand Down
12 changes: 12 additions & 0 deletions wasmtime/component/_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ def add_wasip2(self) -> None:
if err:
raise WasmtimeError._from_ptr(err)

def add_wasi_http(self) -> None:
"""
Adds the WASI HTTP API definitions to this linker.
This adds `wasi:http/types` and `wasi:http/outgoing-handler`.
Requires WASIp2 to be added first via `add_wasip2()`.
"""
self._assert_not_locked()
err = ffi.wasmtime_component_linker_add_wasi_http(self.ptr())
if err:
raise WasmtimeError._from_ptr(err)

def instantiate(self, store: Storelike, component: Component) -> Instance:
"""
Instantiates the given component using this linker within the provided
Expand Down
Loading