Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add source for for wasi-experimental-http-wasmtime.
  • Loading branch information
brendandburns committed Feb 17, 2023
commit d6cea51fc1a96cecaad4b478b4dce45ca2bef84b
24 changes: 24 additions & 0 deletions crates/wasi-experimental-http-wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "wasi-experimental-http-wasmtime"
version = "0.10.0"
authors = [ "Radu Matei <[email protected]>" ]
edition = "2021"
repository = "https://github.com/deislabs/wasi-experimental-http"
license = "MIT"
description = "Experimental HTTP library for WebAssembly in Wasmtime"
readme = "readme.md"

[dependencies]
anyhow = "1.0"
bytes = "1"
futures = "0.3"
http = "0.2"
reqwest = { version = "0.11", default-features = true, features = [
"json",
"blocking",
] }
thiserror = "1.0"
tokio = { version = "1.4.0", features = [ "full" ] }
tracing = { version = "0.1", features = [ "log" ] }
url = "2.2.1"
wasmtime = { workspace = true }
34 changes: 34 additions & 0 deletions crates/wasi-experimental-http-wasmtime/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# `wasi-experimental-http-wasmtime`

![Crates.io](https://img.shields.io/crates/v/wasi-experimental-http-wasmtime)

Experimental HTTP library for WebAssembly in Wasmtime

### Adding support to a Wasmtime runtime

The easiest way to add support is by using the
[Wasmtime linker](https://docs.rs/wasmtime/0.26.0/wasmtime/struct.Linker.html):

```rust
let store = Store::default();
let mut linker = Linker::new(&store);
let wasi = Wasi::new(&store, ctx);

// link the WASI core functions
wasi.add_to_linker(&mut linker)?;

// link the experimental HTTP support
let allowed_hosts = Some(vec!["https://postman-echo.com".to_string()]);
let max_concurrent_requests = Some(42);

let http = HttpCtx::new(allowed_domains, max_concurrent_requests)?;
http.add_to_linker(&mut linker)?;
```

The Wasmtime implementation also enables allowed domains - an optional and
configurable list of domains or hosts that guest modules are allowed to send
requests to. If `None` or an empty vector is passed, guest modules are **NOT**
allowed to make HTTP requests to any server. (Note that the hosts passed MUST
have the protocol also specified - i.e. `https://my-domain.com`, or
`http://192.168.0.1`, and if making requests to a subdomain, the subdomain MUST
be in the allowed list. See the the library tests for more examples).
Loading