WebAssembly / wasi-http

Other
153 stars 24 forks source link

Require network handle #59

Open badeend opened 1 year ago

badeend commented 1 year ago

wasi-sockets requires a network handle to be passed to operations that talk with the outside world. Example: tcp::connect

/// An opaque resource that represents access to (a subset of) the network.
/// This enables context-based security for networking.
/// There is no need for this to map 1:1 to a physical network interface.
resource network

Even though this network resource is defined in the wasi-sockets repo, there is nothing socket-specific about it.

Should wasi-http require this handle too?

Edit: the http proxy world might do fine without, but I'm mainly coming at this from the cli world perspective.

lukewagner commented 1 year ago

(sorry for the delay; I was out to the CG meeting last week)

At least in the current version of the proposal, there's only support for a single default HTTP handler (which can be virtualized using link-time virtualization). In future iterations, we've talked about having multiple HTTP handlers (that can be configured independently), which starts to look somewhat like resource network, but the HTTP backends are distinct concepts and thus I don't think need to share the same resource type.

More generally, since there is a reoccurring pattern here (in which there is an interface that is commonly imported as a global singleton, but for advanced use cases you want to "resource-ify" it), there's an idea to give this pattern first-class support in the component model and WIT by having a built-in way to automatically "resource-ify" any WIT interface to generate a new resource type whose methods correspond to the fields of the original interface. That is outside the Preview 2 timeframe, but it's something we could consider to simplify/regularize WASI proposals in the Preview 3 timeframe.