From c3af8fdc018c3c223563c33fea0eda7c1f687b23 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Thu, 9 Feb 2023 23:08:04 +0100 Subject: [PATCH 01/16] feat: add wasi http experimental --- Cargo.lock | 536 ++++++++++++++++++++++++++++++++++++++++++- host/Cargo.toml | 4 + host/src/http.rs | 34 +++ host/src/lib.rs | 4 + wit/wasi-command.wit | 1 + wit/wasi-http.wit | 37 +++ wit/wasi.wit | 1 + 7 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 host/src/http.rs create mode 100644 wit/wasi-http.wit diff --git a/Cargo.lock b/Cargo.lock index c34186a2..3240eff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,6 +72,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "bincode" version = "1.3.3" @@ -112,6 +118,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + [[package]] name = "cap-fs-ext" version = "1.0.5" @@ -191,6 +203,22 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -477,6 +505,27 @@ dependencies = [ "log", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -497,6 +546,45 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "futures-channel" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" + +[[package]] +name = "futures-sink" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" + +[[package]] +name = "futures-task" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" + +[[package]] +name = "futures-util" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "fxhash" version = "0.2.1" @@ -538,6 +626,25 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "h2" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -580,6 +687,7 @@ dependencies = [ "cap-rand", "cap-std", "is-terminal", + "reqwest", "tempfile", "terminal_size", "test-log", @@ -593,12 +701,83 @@ dependencies = [ "wasmtime", ] +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.14.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "id-arena" version = "2.2.1" @@ -717,6 +896,15 @@ dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -807,6 +995,42 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.42.0", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "num_cpus" version = "1.15.0" @@ -835,6 +1059,51 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +[[package]] +name = "openssl" +version = "0.10.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "paste" version = "1.0.11" @@ -853,6 +1122,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.26" @@ -1022,6 +1297,43 @@ dependencies = [ "winapi", ] +[[package]] +name = "reqwest" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" +dependencies = [ + "base64 0.21.0", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1044,12 +1356,50 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.152" @@ -1070,6 +1420,29 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha2" version = "0.10.6" @@ -1090,6 +1463,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + [[package]] name = "slice-group-by" version = "0.3.0" @@ -1102,6 +1484,16 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1255,7 +1647,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", + "bytes", + "libc", + "memchr", + "mio", "pin-project-lite", + "socket2", "tokio-macros", "windows-sys 0.42.0", ] @@ -1271,6 +1668,30 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "toml" version = "0.5.11" @@ -1280,6 +1701,12 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.37" @@ -1328,6 +1755,12 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + [[package]] name = "typenum" version = "1.16.0" @@ -1393,6 +1826,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "verify" version = "0.1.0" @@ -1408,6 +1847,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1475,6 +1924,72 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + [[package]] name = "wasm-encoder" version = "0.23.0" @@ -1573,7 +2088,7 @@ version = "6.0.0" source = "git+https://github.com/bytecodealliance/wasmtime?branch=release-6.0.0#702edc55f816e5e437c96236eb614de1b41cd66a" dependencies = [ "anyhow", - "base64", + "base64 0.13.1", "bincode", "directories-next", "file-per-thread-logger", @@ -1769,6 +2284,16 @@ dependencies = [ "wast", ] +[[package]] +name = "web-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1881,6 +2406,15 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "winx" version = "0.35.0" diff --git a/host/Cargo.toml b/host/Cargo.toml index 4cdd5b76..9c2223b1 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -16,9 +16,13 @@ wasi-common = { path = "../wasi-common" } wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" } is-terminal = "0.4.1" terminal_size = "0.2.3" +reqwest = { version = "0.11.14", optional = true } [dev-dependencies] test-programs-macros = { path = "../test-programs/macros" } tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt" ]} test-log = { version = "0.2", default-features = false, features = ["trace"] } tempfile = "3.3.0" + +[features] +http = ["dep:reqwest"] diff --git a/host/src/http.rs b/host/src/http.rs new file mode 100644 index 00000000..e18070f2 --- /dev/null +++ b/host/src/http.rs @@ -0,0 +1,34 @@ +use crate::{ + wasi_http::{Request, Response, WasiHttp}, + WasiCtx +}; +use reqwest::{Client, Method}; + +#[async_trait::async_trait] +impl WasiHttp for WasiCtx { + async fn make_request(&mut self, req: Request) -> anyhow::Result { + let client = Client::default(); + let mut builder = client.request( + Method::from_bytes(req.method.as_bytes())?, + req.uri, + ); + for header in req.headers { + builder = builder.header(header.0, header.1); + } + let res = builder.send().await?; + let status = res.status().as_u16(); + let mut headers = vec![]; + for (name, value) in res.headers().iter() { + headers.push(( + name.as_str().to_string(), + value.to_str()?.to_string(), + )); + } + let body = Some(res.bytes().await?.to_vec()); + Ok(Response { + status, + headers: Some(headers), + body, + }) + } +} diff --git a/host/src/lib.rs b/host/src/lib.rs index 40e188d5..63f62bd9 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -1,6 +1,8 @@ mod clocks; mod exit; mod filesystem; +#[cfg(feature = "http")] +mod http; mod io; mod logging; mod poll; @@ -32,5 +34,7 @@ pub fn add_to_linker( wasi_random::add_to_linker(l, f)?; wasi_tcp::add_to_linker(l, f)?; wasi_exit::add_to_linker(l, f)?; + #[cfg(feature = "http")] + wasi_http::add_to_linker(l, f)?; Ok(()) } diff --git a/wit/wasi-command.wit b/wit/wasi-command.wit index 165be9fe..20f75044 100644 --- a/wit/wasi-command.wit +++ b/wit/wasi-command.wit @@ -11,6 +11,7 @@ default world wasi-command { import wasi-ip: pkg.wasi-ip import wasi-dns: pkg.wasi-dns import wasi-exit: pkg.wasi-exit + import wasi-http: pkg.wasi-http export command: func( stdin: u32, // TODO `use` from `wasi-io` diff --git a/wit/wasi-http.wit b/wit/wasi-http.wit new file mode 100644 index 00000000..42bf3bf6 --- /dev/null +++ b/wit/wasi-http.wit @@ -0,0 +1,37 @@ +default interface wasi-http { +/// The HTTP status code. + type http-status = u16 + + /// The HTTP body. + type body = list + + /// The HTTP headers represented as a list of (name, value) pairs. + type headers = list> + + /// The HTTP parameter queries, represented as a list of (name, value) pairs. + type params = list> + + /// The HTTP URI of the current request. + type uri = string + + /// The HTTP method. + type method = string + + /// An HTTP request. + record request { + method: method, + uri: uri, + headers: headers, + params: params, + body: option, + } + + /// An HTTP response. + record response { + status: http-status, + headers: option, + body: option, + } + + make-request: func(req: request) -> response +} diff --git a/wit/wasi.wit b/wit/wasi.wit index 29494cbc..1ce64007 100644 --- a/wit/wasi.wit +++ b/wit/wasi.wit @@ -11,4 +11,5 @@ default world wasi { import wasi-ip: pkg.wasi-ip import wasi-dns: pkg.wasi-dns import wasi-exit: pkg.wasi-exit + import wasi-http: pkg.wasi-http } From e707e138c6f6692c7137c361832eda9b4f77d1b1 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 10 Feb 2023 22:01:16 +0100 Subject: [PATCH 02/16] feat: add bindings crate --- Cargo.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- bindings/Cargo.toml | 10 ++++++++ bindings/src/lib.rs | 10 ++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 bindings/Cargo.toml create mode 100644 bindings/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3240eff4..3103fd25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,6 +585,45 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "futures-channel" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" + +[[package]] +name = "futures-sink" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" + +[[package]] +name = "futures-task" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" + +[[package]] +name = "futures-util" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "fxhash" version = "0.2.1" @@ -1371,6 +1410,21 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1863,6 +1917,13 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi-bindings" +version = "0.0.0" +dependencies = [ + "wit-bindgen-guest-rust", +] + [[package]] name = "wasi-cap-std-sync" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 7a5ba8e3..838005d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version.workspace = true edition.workspace = true [workspace] -members = ["verify", "host", "test-programs", "test-programs/wasi-tests", "wasi-common", "byte-array"] +members = ["verify", "host", "test-programs", "test-programs/wasi-tests", "wasi-common", "byte-array", "bindings"] [workspace.package] version = "0.0.0" diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml new file mode 100644 index 00000000..f9cd023d --- /dev/null +++ b/bindings/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "wasi-bindings" +version.workspace = true +edition.workspace = true + +[dependencies] +wit-bindgen-guest-rust = { git = "https://github.com/bytecodealliance/wit-bindgen", default-features = false, features = ["macros", "realloc"] } + +[lib] +crate-type = ["lib"] diff --git a/bindings/src/lib.rs b/bindings/src/lib.rs new file mode 100644 index 00000000..9a4a5408 --- /dev/null +++ b/bindings/src/lib.rs @@ -0,0 +1,10 @@ +mod bindings { + wit_bindgen_guest_rust::generate!({ + path: "../wit", + world: "wasi", + no_std, + unchecked, + }); +} + +pub use bindings::*; From c5da58378d1a689c6be3773827ad63690c0e3f36 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Sun, 12 Feb 2023 15:56:48 +0100 Subject: [PATCH 03/16] feat: return monadic type for http request --- host/src/http.rs | 16 +++++++++++----- wit/wasi-http.wit | 11 ++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/host/src/http.rs b/host/src/http.rs index e18070f2..7e30d43f 100644 --- a/host/src/http.rs +++ b/host/src/http.rs @@ -1,12 +1,12 @@ use crate::{ - wasi_http::{Request, Response, WasiHttp}, - WasiCtx + wasi_http::{HttpError, Request, Response, WasiHttp}, + HostResult, WasiCtx }; use reqwest::{Client, Method}; #[async_trait::async_trait] impl WasiHttp for WasiCtx { - async fn make_request(&mut self, req: Request) -> anyhow::Result { + async fn make_request(&mut self, req: Request) -> HostResult { let client = Client::default(); let mut builder = client.request( Method::from_bytes(req.method.as_bytes())?, @@ -25,10 +25,16 @@ impl WasiHttp for WasiCtx { )); } let body = Some(res.bytes().await?.to_vec()); - Ok(Response { + Ok(Ok(Response { status, headers: Some(headers), body, - }) + })) + } +} + +impl From for HttpError { + fn from(e: reqwest::Error) -> Self { + Self::UnexpectedError(e.to_string()) } } diff --git a/wit/wasi-http.wit b/wit/wasi-http.wit index 42bf3bf6..a180c2da 100644 --- a/wit/wasi-http.wit +++ b/wit/wasi-http.wit @@ -33,5 +33,14 @@ default interface wasi-http { body: option, } - make-request: func(req: request) -> response + /// HTTP errors returned by the runtime. + variant http-error { + invalid-url(string), + timeout-error(string), + protocol-error(string), + status-error(u16), + unexpected-error(string) + } + + make-request: func(req: request) -> result } From 6b7faa4e652ec4616d8e307d3344bd088bf9a101 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Sun, 12 Feb 2023 16:01:11 +0100 Subject: [PATCH 04/16] chore: rename main http function to send --- host/src/http.rs | 2 +- wit/wasi-http.wit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/host/src/http.rs b/host/src/http.rs index 7e30d43f..17df76bf 100644 --- a/host/src/http.rs +++ b/host/src/http.rs @@ -6,7 +6,7 @@ use reqwest::{Client, Method}; #[async_trait::async_trait] impl WasiHttp for WasiCtx { - async fn make_request(&mut self, req: Request) -> HostResult { + async fn send(&mut self, req: Request) -> HostResult { let client = Client::default(); let mut builder = client.request( Method::from_bytes(req.method.as_bytes())?, diff --git a/wit/wasi-http.wit b/wit/wasi-http.wit index a180c2da..bcbddd00 100644 --- a/wit/wasi-http.wit +++ b/wit/wasi-http.wit @@ -42,5 +42,5 @@ default interface wasi-http { unexpected-error(string) } - make-request: func(req: request) -> result + send: func(req: request) -> result } From 8c6043e6fddc716560aaa8fa16a52bc848d2ca71 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Tue, 14 Feb 2023 00:22:31 +0100 Subject: [PATCH 05/16] chore: update wit-bindgen in bindings crate --- Cargo.lock | 56 +-------------------------------------------- bindings/Cargo.toml | 2 +- bindings/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3103fd25..b4ee3571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,45 +585,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "futures-channel" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" - -[[package]] -name = "futures-sink" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" - -[[package]] -name = "futures-task" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" - -[[package]] -name = "futures-util" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" -dependencies = [ - "futures-core", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "fxhash" version = "0.2.1" @@ -1410,21 +1371,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "ryu" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" - -[[package]] -name = "schannel" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" -dependencies = [ - "windows-sys", -] - [[package]] name = "scopeguard" version = "1.1.0" @@ -1921,7 +1867,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" name = "wasi-bindings" version = "0.0.0" dependencies = [ - "wit-bindgen-guest-rust", + "wit-bindgen", ] [[package]] diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml index f9cd023d..ec084501 100644 --- a/bindings/Cargo.toml +++ b/bindings/Cargo.toml @@ -4,7 +4,7 @@ version.workspace = true edition.workspace = true [dependencies] -wit-bindgen-guest-rust = { git = "https://github.com/bytecodealliance/wit-bindgen", default-features = false, features = ["macros", "realloc"] } +wit-bindgen = { version = "0.3.0", default-features = false, features = ["macros", "realloc"] } [lib] crate-type = ["lib"] diff --git a/bindings/src/lib.rs b/bindings/src/lib.rs index 9a4a5408..250eb878 100644 --- a/bindings/src/lib.rs +++ b/bindings/src/lib.rs @@ -1,5 +1,5 @@ mod bindings { - wit_bindgen_guest_rust::generate!({ + wit_bindgen::generate!({ path: "../wit", world: "wasi", no_std, From 9dc2233e19f7b4fff25327b8957e280f093f606f Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Tue, 14 Feb 2023 13:20:59 +0100 Subject: [PATCH 06/16] chore: change http method to enum --- host/src/http.rs | 22 ++++++++++++++++++---- wit/wasi-http.wit | 10 +++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/host/src/http.rs b/host/src/http.rs index 17df76bf..be2702b5 100644 --- a/host/src/http.rs +++ b/host/src/http.rs @@ -1,15 +1,14 @@ use crate::{ - wasi_http::{HttpError, Request, Response, WasiHttp}, + wasi_http::{HttpError, Method, Request, Response, WasiHttp}, HostResult, WasiCtx }; -use reqwest::{Client, Method}; #[async_trait::async_trait] impl WasiHttp for WasiCtx { async fn send(&mut self, req: Request) -> HostResult { - let client = Client::default(); + let client = reqwest::Client::default(); let mut builder = client.request( - Method::from_bytes(req.method.as_bytes())?, + req.method.into(), req.uri, ); for header in req.headers { @@ -38,3 +37,18 @@ impl From for HttpError { Self::UnexpectedError(e.to_string()) } } + +impl From for reqwest::Method { + fn from(method: Method) -> Self { + match method { + Method::Get => reqwest::Method::GET, + Method::Post => reqwest::Method::POST, + Method::Put => reqwest::Method::PUT, + Method::Delete => reqwest::Method::DELETE, + Method::Patch => reqwest::Method::PATCH, + Method::Head => reqwest::Method::HEAD, + Method::Options => reqwest::Method::OPTIONS, + _ => panic!("failed due to unsupported method, currently supported methods are: GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS"), + } + } +} diff --git a/wit/wasi-http.wit b/wit/wasi-http.wit index bcbddd00..f65258db 100644 --- a/wit/wasi-http.wit +++ b/wit/wasi-http.wit @@ -15,7 +15,15 @@ default interface wasi-http { type uri = string /// The HTTP method. - type method = string + enum method { + get, + post, + put, + delete, + patch, + head, + options, + } /// An HTTP request. record request { From 72116e390bb6e07fdf7f14884dfd725e8a01eb3b Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Tue, 14 Feb 2023 13:21:26 +0100 Subject: [PATCH 07/16] chore: remove http status error --- host/src/http.rs | 1 - wit/wasi-http.wit | 1 - 2 files changed, 2 deletions(-) diff --git a/host/src/http.rs b/host/src/http.rs index be2702b5..ed5c59f0 100644 --- a/host/src/http.rs +++ b/host/src/http.rs @@ -48,7 +48,6 @@ impl From for reqwest::Method { Method::Patch => reqwest::Method::PATCH, Method::Head => reqwest::Method::HEAD, Method::Options => reqwest::Method::OPTIONS, - _ => panic!("failed due to unsupported method, currently supported methods are: GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS"), } } } diff --git a/wit/wasi-http.wit b/wit/wasi-http.wit index f65258db..faf57fca 100644 --- a/wit/wasi-http.wit +++ b/wit/wasi-http.wit @@ -46,7 +46,6 @@ default interface wasi-http { invalid-url(string), timeout-error(string), protocol-error(string), - status-error(u16), unexpected-error(string) } From bae55454c1c3017cec538ad05c8b99bd3c703a6c Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Thu, 23 Feb 2023 23:08:51 +0100 Subject: [PATCH 08/16] feat: use new wasi-http wit definition --- wit/wasi-command.wit | 2 +- wit/wasi-default-upstream-http.wit | 138 +++++++++++++++++++++++++++++ wit/wasi-http.wit | 53 ----------- wit/wasi.wit | 2 +- 4 files changed, 140 insertions(+), 55 deletions(-) create mode 100644 wit/wasi-default-upstream-http.wit delete mode 100644 wit/wasi-http.wit diff --git a/wit/wasi-command.wit b/wit/wasi-command.wit index 5bff853b..1ed556b8 100644 --- a/wit/wasi-command.wit +++ b/wit/wasi-command.wit @@ -14,7 +14,7 @@ default world wasi-command { import wasi-dns: pkg.wasi-dns import wasi-exit: pkg.wasi-exit import wasi-environment: pkg.wasi-environment - import wasi-http: pkg.wasi-http + import wasi-default-upstream-http: pkg.wasi-default-upstream-http export command: func( stdin: u32, // TODO `use` from `wasi-io` diff --git a/wit/wasi-default-upstream-http.wit b/wit/wasi-default-upstream-http.wit new file mode 100644 index 00000000..b536f4c0 --- /dev/null +++ b/wit/wasi-default-upstream-http.wit @@ -0,0 +1,138 @@ +// The `wasi:http/outgoing-handler` interface is meant to be imported by +// components and implemented by the host. +// +// NOTE: in Preview3, this interface will be merged with +// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface +// that takes a `request` parameter and returns a `response` result. +// +default interface outgoing-handler { + + // This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + // This type corresponds to HTTP standard Related Schemes. + variant scheme { + HTTP, + HTTPS, + other(string) + } + + // This type enumerates the different kinds of errors that may occur when + // initially returning a response. + variant error { + invalid-url(string), + timeout-error(string), + protocol-error(string), + status-error(u16), + unexpected-error(string) + } + + // This following block defines the `fields` resource which corresponds to + // HTTP standard Fields. Soon, when resource types are added, the `type + // fields = u32` type alias can be replaced by a proper `resource fields` + // definition containing all the functions using the method syntactic sugar. + type fields = u32 + drop-fields: func(fields: fields) + new-fields: func(entries: list>) -> fields + fields-get: func(fields: fields, name: string) -> list + fields-set: func(fields: fields, name: string, value: list) + fields-delete: func(fields: fields, name: string) + fields-append: func(fields: fields, name: string, value: string) + fields-entries: func(fields: fields) -> list> + fields-clone: func(fields: fields) -> fields + + type headers = fields + type trailers = fields + + // The following block defines the `body` type which corresponds to the HTTP + // standard Contents. With Preview3, all of these fields can be replaced by a + // single type definition: + // + // type body = stream> + // + // In the interim, we need to use separate `input-stream` and `output-stream` + // resource types defined by `wasi:io/streams`. The `finish-` functions + // emulate the stream's result value and MUST be called exactly once after + // the final read/write from/to the stream before dropping the stream. + use pkg.wasi-io.{input-stream, output-stream} + type incoming-body = input-stream + type outgoing-body = output-stream + finish-incoming-body: func(body: incoming-body) -> option + finish-outgoing-body: func(body: outgoing-body, trailers: option) + + // The following block defines the `incoming-request` and `outgoing-request` + // resource types that correspond to HTTP standard Requests. Soon, when + // resource types are added, the `u32` type aliases can be replaced by + // proper `resource` type definitions containing all the functions as + // methods. Later, Preview2 will allow both types to be merged together into + // a single `request` type (that uses the single `body` type mentioned + // above). The `consume` and `write-body` methods may only be called once + // (and return failure thereafter). + type incoming-request = u32 + type outgoing-request = u32 + drop-incoming-request: func(request: incoming-request) + drop-outgoing-request: func(request: outgoing-request) + incoming-request-method: func(request: incoming-request) -> method + incoming-request-path: func(request: incoming-request) -> string + incoming-request-scheme: func(request: incoming-request) -> option + incoming-request-authority: func(request: incoming-request) -> string + incoming-request-headers: func(request: incoming-request) -> headers + incoming-request-consume: func(request: incoming-request) -> result + new-outgoing-request: func( + method: method, + path: string, + scheme: option, + authority: string, + headers: headers + ) -> outgoing-request + outgoing-request-write-body: func(request: outgoing-request) -> result + + // The following block defines a special resource type used by the + // `wasi:http/outgoing-handler` interface. When resource types are added, this + // block can be replaced by a proper `resource response-outparam { ... }` + // definition. Later, with Preview3, the need for an outparam goes away entirely + // (the `wasi:http/handler` interface used for both incoming and outgoing can + // simply return a `body`). + type response-outparam = u32 + drop-response-outparam: func(response: response-outparam) + set-response-outparam: func(response: result) -> result + + // This type corresponds to the HTTP standard Status Code. + type status-code = u16 + + // The following block defines the `incoming-response` and `outgoing-response` + // resource types that correspond to HTTP standard Responses. Soon, when + // resource types are added, the `u32` type aliases can be replaced by proper + // `resource` type definitions containing all the functions as methods. Later, + // Preview2 will allow both types to be merged together into a single `response` + // type (that uses the single `body` type mentioned above). The `consume` and + // `write-body` methods may only be called once (and return failure thereafter). + type incoming-response = u32 + type outgoing-response = u32 + drop-incoming-response: func(response: incoming-response) + drop-outgoing-response: func(response: outgoing-response) + incoming-response-status: func(response: incoming-response) -> status-code + incoming-response-headers: func(response: incoming-response) -> headers + incoming-response-consume: func(response: incoming-response) -> result + new-outgoing-response: func( + status-code: status-code, + headers: headers + ) -> outgoing-response + outgoing-response-write-body: func(response: outgoing-response) -> result + + // The parameter and result types of the `handle` function allow the caller + // to concurrently stream the bodies of the outgoing request and the incoming + // response. + handle: func(request: outgoing-request) -> result +} diff --git a/wit/wasi-http.wit b/wit/wasi-http.wit deleted file mode 100644 index faf57fca..00000000 --- a/wit/wasi-http.wit +++ /dev/null @@ -1,53 +0,0 @@ -default interface wasi-http { -/// The HTTP status code. - type http-status = u16 - - /// The HTTP body. - type body = list - - /// The HTTP headers represented as a list of (name, value) pairs. - type headers = list> - - /// The HTTP parameter queries, represented as a list of (name, value) pairs. - type params = list> - - /// The HTTP URI of the current request. - type uri = string - - /// The HTTP method. - enum method { - get, - post, - put, - delete, - patch, - head, - options, - } - - /// An HTTP request. - record request { - method: method, - uri: uri, - headers: headers, - params: params, - body: option, - } - - /// An HTTP response. - record response { - status: http-status, - headers: option, - body: option, - } - - /// HTTP errors returned by the runtime. - variant http-error { - invalid-url(string), - timeout-error(string), - protocol-error(string), - unexpected-error(string) - } - - send: func(req: request) -> result -} diff --git a/wit/wasi.wit b/wit/wasi.wit index c78a6647..d6223f3a 100644 --- a/wit/wasi.wit +++ b/wit/wasi.wit @@ -14,5 +14,5 @@ default world wasi { import wasi-dns: pkg.wasi-dns import wasi-exit: pkg.wasi-exit import wasi-environment: pkg.wasi-environment - import wasi-http: pkg.wasi-http + import wasi-default-upstream-http: pkg.wasi-default-upstream-http } From 1e38e2329310a37665b83dcbc0dc3e7dde404573 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Tue, 14 Mar 2023 01:45:04 +0100 Subject: [PATCH 09/16] chore: add basic scaffolding for wasi http --- Cargo.lock | 436 ++++++++++++------ host/src/default_outgoing_http.rs | 42 ++ host/src/http.rs | 53 +-- host/src/lib.rs | 4 + wit/command.wit | 3 +- ...fault-upstream-http.wit => http-types.wit} | 97 ++-- wit/deps/http/incoming-handler.wit | 24 + wit/deps/http/outgoing-handler.wit | 18 + wit/reactor.wit | 3 +- 9 files changed, 440 insertions(+), 240 deletions(-) create mode 100644 host/src/default_outgoing_http.rs rename wit/deps/http/{default-upstream-http.wit => http-types.wit} (56%) create mode 100644 wit/deps/http/incoming-handler.wit create mode 100644 wit/deps/http/outgoing-handler.wit diff --git a/Cargo.lock b/Cargo.lock index 13f67679..b7aad7bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" [[package]] name = "async-trait" -version = "0.1.64" +version = "0.1.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" +checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" dependencies = [ "proc-macro2", "quote", @@ -66,12 +66,6 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" -[[package]] -name = "base64" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" - [[package]] name = "bincode" version = "1.3.3" @@ -89,9 +83,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] @@ -112,11 +106,17 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + [[package]] name = "camino" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6031a462f977dd38968b6f23378356512feeace69cef817e1a4475108093cec3" +checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2" dependencies = [ "serde", ] @@ -357,9 +357,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" dependencies = [ "cfg-if", "crossbeam-utils", @@ -367,9 +367,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -378,22 +378,22 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.13" +version = "0.9.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset 0.7.1", + "memoffset", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.14" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if", ] @@ -496,9 +496,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] @@ -567,36 +567,36 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" [[package]] name = "futures-sink" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" +checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" [[package]] name = "futures-task" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" [[package]] name = "futures-util" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-core", "futures-task", @@ -647,9 +647,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" dependencies = [ "bytes", "fnv", @@ -711,6 +711,7 @@ dependencies = [ "async-trait", "cap-rand", "cap-std", + "reqwest", "tempfile", "test-log", "test-programs-macros", @@ -725,9 +726,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -765,9 +766,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.24" +version = "0.14.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" +checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" dependencies = [ "bytes", "futures-channel", @@ -848,9 +849,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" dependencies = [ "libc", "windows-sys 0.45.0", @@ -864,9 +865,9 @@ checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", @@ -885,9 +886,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "ittapi" @@ -911,9 +912,9 @@ dependencies = [ [[package]] name = "jobserver" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" dependencies = [ "libc", ] @@ -941,9 +942,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "linux-raw-sys" @@ -999,15 +1000,6 @@ dependencies = [ "rustix", ] -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.8.0" @@ -1025,14 +1017,14 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mio" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", "wasi", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -1086,9 +1078,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "openssl" @@ -1137,9 +1129,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" [[package]] name = "percent-encoding" @@ -1173,9 +1165,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] @@ -1202,9 +1194,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -1241,9 +1233,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" dependencies = [ "either", "rayon-core", @@ -1251,9 +1243,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.2" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -1265,7 +1257,7 @@ dependencies = [ name = "reactor-tests" version = "0.1.0" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.4.0", ] [[package]] @@ -1326,22 +1318,13 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "reqwest" version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" dependencies = [ - "base64 0.21.0", + "base64", "bytes", "encoding_rs", "futures-core", @@ -1380,9 +1363,9 @@ checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustix" -version = "0.36.8" +version = "0.36.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" dependencies = [ "bitflags", "errno", @@ -1396,9 +1379,18 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "schannel" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] [[package]] name = "scopeguard" @@ -1406,29 +1398,52 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.152" +version = "1.0.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "71f2b4817415c6d4210bfe1c7bfcf4801b2d904cb4d0e1a8fdb651013c9e86b8" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "d071a94a3fac4aff69d023a7f411e33f40f3483f8c5190b1953822b6b76d7630" dependencies = [ "proc-macro2", "quote", @@ -1437,10 +1452,22 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.93" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ + "form_urlencoded", "itoa", "ryu", "serde", @@ -1468,9 +1495,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] @@ -1489,9 +1516,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", "winapi", @@ -1505,9 +1532,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" -version = "1.0.107" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -1538,16 +1565,15 @@ checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "tempfile" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ "cfg-if", "fastrand", - "libc", "redox_syscall", - "remove_dir_all", - "winapi", + "rustix", + "windows-sys 0.42.0", ] [[package]] @@ -1577,7 +1603,7 @@ dependencies = [ "cap-std", "getrandom", "rustix", - "wit-bindgen", + "wit-bindgen 0.4.0", ] [[package]] @@ -1587,23 +1613,23 @@ dependencies = [ "cargo_metadata", "heck", "quote", - "wit-component", + "wit-component 0.7.4", ] [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", @@ -1637,9 +1663,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.25.0" +version = "1.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" +checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" dependencies = [ "autocfg", "bytes", @@ -1649,7 +1675,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -1773,15 +1799,15 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" +checksum = "524b68aca1d05e03fdf03fcdce2c6c94b6daf6d16861ddaa7e4f2b6638a9052c" [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-normalization" @@ -1862,7 +1888,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" name = "wasi-bindings" version = "0.0.0" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.3.0", ] [[package]] @@ -1923,7 +1949,7 @@ dependencies = [ "object 0.29.0", "wasi", "wasm-encoder 0.24.1", - "wit-bindgen", + "wit-bindgen 0.4.0", ] [[package]] @@ -1992,6 +2018,15 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "wasm-encoder" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c3e4bc09095436c8e7584d86d33e6c3ee67045af8fb262cbb9cc321de553428" +dependencies = [ + "leb128", +] + [[package]] name = "wasm-encoder" version = "0.24.1" @@ -2010,6 +2045,19 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-metadata" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139cad89459dd2ae22ec2ebd439db058f3b0cab7bef98e9856ff7c446ec60b2a" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "wasm-encoder 0.23.0", + "wasmparser 0.100.0", +] + [[package]] name = "wasm-metadata" version = "0.3.1" @@ -2032,6 +2080,16 @@ dependencies = [ "indexmap", ] +[[package]] +name = "wasmparser" +version = "0.100.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64b20236ab624147dfbb62cf12a19aaf66af0e41b8398838b66e997d07d269d4" +dependencies = [ + "indexmap", + "url", +] + [[package]] name = "wasmparser" version = "0.102.0" @@ -2044,9 +2102,9 @@ dependencies = [ [[package]] name = "wasmprinter" -version = "0.2.53" +version = "0.2.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa44d546e4e4479f2e91035fa497c0a05cffbf22413ad05bf0b06a789b9118f" +checksum = "2dc17ae63836d010a2bf001c26a5fedbb9a05e5f71117fb63e0ab878bfbe1ca3" dependencies = [ "anyhow", "wasmparser 0.102.0", @@ -2099,7 +2157,7 @@ version = "8.0.0" source = "git+https://github.com/bytecodealliance/wasmtime?rev=8d3a881b524d56498dfc71b65818b2abbeb1da44#8d3a881b524d56498dfc71b65818b2abbeb1da44" dependencies = [ "anyhow", - "base64 0.13.1", + "base64", "bincode", "directories-next", "file-per-thread-logger", @@ -2242,7 +2300,7 @@ dependencies = [ "log", "mach", "memfd", - "memoffset 0.8.0", + "memoffset", "paste", "rand", "rustix", @@ -2362,9 +2420,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -2377,45 +2435,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winreg" @@ -2437,6 +2495,16 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "wit-bindgen" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c528d2ebfc375d928a6682a46acab1c125071908fa91378a63feca794c3c515a" +dependencies = [ + "bitflags", + "wit-bindgen-guest-rust-macro", +] + [[package]] name = "wit-bindgen" version = "0.4.0" @@ -2447,6 +2515,17 @@ dependencies = [ "wit-bindgen-rust-macro", ] +[[package]] +name = "wit-bindgen-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea1d49787508c06dfbeeb2c6599a20fc475547b102fc3e8637ada7d67bb62969" +dependencies = [ + "anyhow", + "wit-component 0.6.0", + "wit-parser", +] + [[package]] name = "wit-bindgen-core" version = "0.4.0" @@ -2454,10 +2533,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef177b73007d86c720931d0e2ea7e30eb8c9776e58361717743fc1e83cfacfe5" dependencies = [ "anyhow", - "wit-component", + "wit-component 0.7.4", "wit-parser", ] +[[package]] +name = "wit-bindgen-gen-guest-rust" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae66d141c30d008ae9ef39b266b34c481db8c0aaa688c1431d04b8b8f3247d4" +dependencies = [ + "heck", + "wit-bindgen-core 0.3.0", + "wit-bindgen-gen-rust-lib", + "wit-component 0.6.0", +] + +[[package]] +name = "wit-bindgen-gen-rust-lib" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7e9138be66f508243c62d3d565fc03ce43ed04f3fc19a5fe8d3fb7f69f3fe4" +dependencies = [ + "heck", + "wit-bindgen-core 0.3.0", +] + +[[package]] +name = "wit-bindgen-guest-rust-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9719f2ff3068780f21202b62c968b3a34dc2a302874e327302d82abfd478313" +dependencies = [ + "anyhow", + "proc-macro2", + "syn", + "wit-bindgen-core 0.3.0", + "wit-bindgen-gen-guest-rust", + "wit-component 0.6.0", +] + [[package]] name = "wit-bindgen-rust" version = "0.4.0" @@ -2465,10 +2580,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efdf5b00935b7b52d0e56cae1960f8ac13019a285f5aa762ff6bd7139a5c28a2" dependencies = [ "heck", - "wasm-metadata", - "wit-bindgen-core", + "wasm-metadata 0.3.1", + "wit-bindgen-core 0.4.0", "wit-bindgen-rust-lib", - "wit-component", + "wit-component 0.7.4", ] [[package]] @@ -2478,7 +2593,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab0a8f4b5fb1820b9d232beb122936425f72ec8fe6acb56e5d8782cfe55083da" dependencies = [ "heck", - "wit-bindgen-core", + "wit-bindgen-core 0.4.0", ] [[package]] @@ -2490,16 +2605,33 @@ dependencies = [ "anyhow", "proc-macro2", "syn", - "wit-bindgen-core", + "wit-bindgen-core 0.4.0", "wit-bindgen-rust", - "wit-component", + "wit-component 0.7.4", +] + +[[package]] +name = "wit-component" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0404e6b5c75131ae4bc05de7a14917a62030f67625804f4530ab39368321d857" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "url", + "wasm-encoder 0.23.0", + "wasm-metadata 0.1.2", + "wasmparser 0.100.0", + "wit-parser", ] [[package]] name = "wit-component" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e93680c292afbad08ec462c901714ba53e5109076003e53a82e584f3aa319bc" +checksum = "ed04310239706efc71cc8b995cb0226089c5b5fd260c3bd800a71486bd3cec97" dependencies = [ "anyhow", "bitflags", @@ -2507,7 +2639,7 @@ dependencies = [ "log", "url", "wasm-encoder 0.25.0", - "wasm-metadata", + "wasm-metadata 0.3.1", "wasmparser 0.102.0", "wit-parser", ] diff --git a/host/src/default_outgoing_http.rs b/host/src/default_outgoing_http.rs new file mode 100644 index 00000000..4f49462a --- /dev/null +++ b/host/src/default_outgoing_http.rs @@ -0,0 +1,42 @@ +use crate::{ + wasi, + wasi::http_types::{ + Error as HttpError, FutureIncomingResponse as Response, Method, OutgoingRequest as Request, + RequestOptions, + }, + WasiCtx, +}; + +#[async_trait::async_trait] +impl wasi::default_outgoing_http::Host for WasiCtx { + async fn handle<'a>( + &'a mut self, + _req: Request, + _options: Option, + ) -> wasmtime::Result { + todo!() + } +} + +impl From for HttpError { + fn from(e: reqwest::Error) -> Self { + Self::UnexpectedError(e.to_string()) + } +} + +impl From for reqwest::Method { + fn from(method: Method) -> Self { + match method { + Method::Get => reqwest::Method::GET, + Method::Post => reqwest::Method::POST, + Method::Put => reqwest::Method::PUT, + Method::Delete => reqwest::Method::DELETE, + Method::Patch => reqwest::Method::PATCH, + Method::Connect => reqwest::Method::CONNECT, + Method::Trace => reqwest::Method::TRACE, + Method::Head => reqwest::Method::HEAD, + Method::Options => reqwest::Method::OPTIONS, + _ => panic!("failed due to unsupported method, currently supported methods are: GET, POST, PUT, DELETE, PATCH, CONNECT, TRACE, HEAD, and OPTIONS"), + } + } +} diff --git a/host/src/http.rs b/host/src/http.rs index ed5c59f0..6fe60870 100644 --- a/host/src/http.rs +++ b/host/src/http.rs @@ -1,53 +1,12 @@ use crate::{ - wasi_http::{HttpError, Method, Request, Response, WasiHttp}, - HostResult, WasiCtx + wasi, + wasi::http_types::{IncomingRequest as Request, ResponseOutparam as Response}, + WasiCtx, }; #[async_trait::async_trait] -impl WasiHttp for WasiCtx { - async fn send(&mut self, req: Request) -> HostResult { - let client = reqwest::Client::default(); - let mut builder = client.request( - req.method.into(), - req.uri, - ); - for header in req.headers { - builder = builder.header(header.0, header.1); - } - let res = builder.send().await?; - let status = res.status().as_u16(); - let mut headers = vec![]; - for (name, value) in res.headers().iter() { - headers.push(( - name.as_str().to_string(), - value.to_str()?.to_string(), - )); - } - let body = Some(res.bytes().await?.to_vec()); - Ok(Ok(Response { - status, - headers: Some(headers), - body, - })) - } -} - -impl From for HttpError { - fn from(e: reqwest::Error) -> Self { - Self::UnexpectedError(e.to_string()) - } -} - -impl From for reqwest::Method { - fn from(method: Method) -> Self { - match method { - Method::Get => reqwest::Method::GET, - Method::Post => reqwest::Method::POST, - Method::Put => reqwest::Method::PUT, - Method::Delete => reqwest::Method::DELETE, - Method::Patch => reqwest::Method::PATCH, - Method::Head => reqwest::Method::HEAD, - Method::Options => reqwest::Method::OPTIONS, - } +impl wasi::http::Host for WasiCtx { + async fn handle<'a>(&'a mut self, _req: Request, _resp: Response) -> anyhow::Result<()> { + todo!() } } diff --git a/host/src/lib.rs b/host/src/lib.rs index 3bd0a801..64636527 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -1,4 +1,6 @@ mod clocks; +#[cfg(feature = "http")] +mod default_outgoing_http; mod env; mod exit; mod filesystem; @@ -48,6 +50,8 @@ pub fn add_to_linker( wasi::environment::add_to_linker(l, f)?; wasi::environment_preopens::add_to_linker(l, f)?; #[cfg(feature = "http")] + wasi::default_outgoing_http::add_to_linker(l, f)?; + #[cfg(feature = "http")] wasi::http::add_to_linker(l, f)?; Ok(()) } diff --git a/wit/command.wit b/wit/command.wit index 949a105a..082efd5f 100644 --- a/wit/command.wit +++ b/wit/command.wit @@ -15,7 +15,8 @@ default world command { import random: random.random import poll: poll.poll import streams: io.streams - import default-upstream-http: http.default-upstream-http + import default-outgoing-http: http.outgoing-handler + import http: http.incoming-handler import environment: pkg.environment import environment-preopens: pkg.environment-preopens import exit: pkg.exit diff --git a/wit/deps/http/default-upstream-http.wit b/wit/deps/http/http-types.wit similarity index 56% rename from wit/deps/http/default-upstream-http.wit rename to wit/deps/http/http-types.wit index b536f4c0..93150d11 100644 --- a/wit/deps/http/default-upstream-http.wit +++ b/wit/deps/http/http-types.wit @@ -1,11 +1,9 @@ -// The `wasi:http/outgoing-handler` interface is meant to be imported by -// components and implemented by the host. -// -// NOTE: in Preview3, this interface will be merged with -// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface -// that takes a `request` parameter and returns a `response` result. -// -default interface outgoing-handler { +// The `wasi:http/types` interface is meant to be imported by components to +// define the HTTP resource types and operations used by the component's +// imported and exported interfaces. +default interface http-types { + use io.streams.{input-stream, output-stream} + use poll.poll.{pollable} // This type corresponds to HTTP standard Methods. variant method { @@ -28,13 +26,13 @@ default interface outgoing-handler { other(string) } + // TODO: perhaps better align with HTTP semantics? // This type enumerates the different kinds of errors that may occur when // initially returning a response. variant error { invalid-url(string), timeout-error(string), protocol-error(string), - status-error(u16), unexpected-error(string) } @@ -55,55 +53,69 @@ default interface outgoing-handler { type headers = fields type trailers = fields - // The following block defines the `body` type which corresponds to the HTTP - // standard Contents. With Preview3, all of these fields can be replaced by a - // single type definition: - // - // type body = stream> - // - // In the interim, we need to use separate `input-stream` and `output-stream` - // resource types defined by `wasi:io/streams`. The `finish-` functions - // emulate the stream's result value and MUST be called exactly once after - // the final read/write from/to the stream before dropping the stream. - use pkg.wasi-io.{input-stream, output-stream} - type incoming-body = input-stream - type outgoing-body = output-stream - finish-incoming-body: func(body: incoming-body) -> option - finish-outgoing-body: func(body: outgoing-body, trailers: option) + // The following block defines stream types which corresponds to the HTTP + // standard Contents and Trailers. With Preview3, all of these fields can be + // replaced by a stream>. In the interim, we need to + // build on separate resource types defined by `wasi:io/streams`. The + // `finish-` functions emulate the stream's result value and MUST be called + // exactly once after the final read/write from/to the stream before dropping + // the stream. + type incoming-stream = input-stream + type outgoing-stream = output-stream + finish-incoming-stream: func(s: incoming-stream) -> option + finish-outgoing-stream: func(s: outgoing-stream, trailers: option) // The following block defines the `incoming-request` and `outgoing-request` // resource types that correspond to HTTP standard Requests. Soon, when // resource types are added, the `u32` type aliases can be replaced by // proper `resource` type definitions containing all the functions as // methods. Later, Preview2 will allow both types to be merged together into - // a single `request` type (that uses the single `body` type mentioned - // above). The `consume` and `write-body` methods may only be called once - // (and return failure thereafter). + // a single `request` type (that uses the single `stream` type mentioned + // above). The `consume` and `write` methods may only be called once (and + // return failure thereafter). type incoming-request = u32 type outgoing-request = u32 drop-incoming-request: func(request: incoming-request) drop-outgoing-request: func(request: outgoing-request) incoming-request-method: func(request: incoming-request) -> method incoming-request-path: func(request: incoming-request) -> string + incoming-request-query: func(request: incoming-request) -> string incoming-request-scheme: func(request: incoming-request) -> option incoming-request-authority: func(request: incoming-request) -> string incoming-request-headers: func(request: incoming-request) -> headers - incoming-request-consume: func(request: incoming-request) -> result + incoming-request-consume: func(request: incoming-request) -> result new-outgoing-request: func( method: method, path: string, + query: string, scheme: option, authority: string, headers: headers ) -> outgoing-request - outgoing-request-write-body: func(request: outgoing-request) -> result + outgoing-request-write: func(request: outgoing-request) -> result + + // Additional optional parameters that can be set when making a request. + record request-options { + // The following timeouts are specific to the HTTP protocol and work + // independently of the overall timeouts passed to `io.poll.poll-oneoff`. + + // The timeout for the initial connect. + connect-timeout-ms: option, + + // The timeout for receiving the first byte of the response body. + first-byte-timeout-ms: option, + + // The timeout for receiving the next chunk of bytes in the response body + // stream. + between-bytes-timeout-ms: option + } // The following block defines a special resource type used by the - // `wasi:http/outgoing-handler` interface. When resource types are added, this + // `wasi:http/incoming-handler` interface. When resource types are added, this // block can be replaced by a proper `resource response-outparam { ... }` // definition. Later, with Preview3, the need for an outparam goes away entirely // (the `wasi:http/handler` interface used for both incoming and outgoing can - // simply return a `body`). + // simply return a `stream`). type response-outparam = u32 drop-response-outparam: func(response: response-outparam) set-response-outparam: func(response: result) -> result @@ -116,23 +128,30 @@ default interface outgoing-handler { // resource types are added, the `u32` type aliases can be replaced by proper // `resource` type definitions containing all the functions as methods. Later, // Preview2 will allow both types to be merged together into a single `response` - // type (that uses the single `body` type mentioned above). The `consume` and - // `write-body` methods may only be called once (and return failure thereafter). + // type (that uses the single `stream` type mentioned above). The `consume` and + // `write` methods may only be called once (and return failure thereafter). type incoming-response = u32 type outgoing-response = u32 drop-incoming-response: func(response: incoming-response) drop-outgoing-response: func(response: outgoing-response) incoming-response-status: func(response: incoming-response) -> status-code incoming-response-headers: func(response: incoming-response) -> headers - incoming-response-consume: func(response: incoming-response) -> result + incoming-response-consume: func(response: incoming-response) -> result new-outgoing-response: func( status-code: status-code, headers: headers ) -> outgoing-response - outgoing-response-write-body: func(response: outgoing-response) -> result + outgoing-response-write: func(response: outgoing-response) -> result - // The parameter and result types of the `handle` function allow the caller - // to concurrently stream the bodies of the outgoing request and the incoming - // response. - handle: func(request: outgoing-request) -> result + // The following block defines a special resource type used by the + // `wasi:http/outgoing-handler` interface to emulate + // `future>` in advance of Preview3. Given a + // `future-incoming-response`, the client can call the non-blocking `get` + // method to get the result if it is available. If the result is not available, + // the client can call `listen` to get a `pollable` that can be passed to + // `io.poll.poll-oneoff`. + type future-incoming-response = u32 + drop-future-incoming-response: func(f: future-incoming-response) + future-incoming-response-get: func(f: future-incoming-response) -> option> + listen-to-future-incoming-response: func(f: future-incoming-response) -> pollable } diff --git a/wit/deps/http/incoming-handler.wit b/wit/deps/http/incoming-handler.wit new file mode 100644 index 00000000..25f79806 --- /dev/null +++ b/wit/deps/http/incoming-handler.wit @@ -0,0 +1,24 @@ +// The `wasi:http/incoming-handler` interface is meant to be exported by +// components and called by the host in response to a new incoming HTTP +// response. +// +// NOTE: in Preview3, this interface will be merged with +// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface +// that takes a `request` parameter and returns a `response` result. +// +default interface incoming-handler { + use pkg.http-types.{incoming-request, response-outparam} + + // The `handle` function takes an outparam instead of returning its response + // so that the component may stream its response while streaming any other + // request or response bodies. The callee MUST write a response to the + // `response-out` and then finish the response before returning. The `handle` + // function is allowed to continue execution after finishing the response's + // output stream. While this post-response execution is taken off the + // critical path, since there is no return value, there is no way to report + // its success or failure. + handle: func( + request: incoming-request, + response-out: response-outparam + ) +} diff --git a/wit/deps/http/outgoing-handler.wit b/wit/deps/http/outgoing-handler.wit new file mode 100644 index 00000000..33015b6c --- /dev/null +++ b/wit/deps/http/outgoing-handler.wit @@ -0,0 +1,18 @@ +// The `wasi:http/outgoing-handler` interface is meant to be imported by +// components and implemented by the host. +// +// NOTE: in Preview3, this interface will be merged with +// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface +// that takes a `request` parameter and returns a `response` result. +// +default interface outgoing-handler { + use pkg.http-types.{outgoing-request, request-options, future-incoming-response} + + // The parameter and result types of the `handle` function allow the caller + // to concurrently stream the bodies of the outgoing request and the incoming + // response. + handle: func( + request: outgoing-request, + options: option + ) -> future-incoming-response +} diff --git a/wit/reactor.wit b/wit/reactor.wit index 7c1a40a8..fdc22912 100644 --- a/wit/reactor.wit +++ b/wit/reactor.wit @@ -15,7 +15,8 @@ default world reactor { import random: random.random import poll: poll.poll import streams: io.streams - import default-upstream-http: http.default-upstream-http + import default-outgoing-http: http.outgoing-handler + import http: http.incoming-handler import environment: pkg.environment import environment-preopens: pkg.environment-preopens import exit: pkg.exit From 0bb1f0e12dba8497a16d4a2fc4cfee9930bd4425 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:01:54 +0100 Subject: [PATCH 10/16] chore: revert rename for http types --- wit/deps/http/incoming-handler.wit | 2 +- wit/deps/http/outgoing-handler.wit | 2 +- wit/deps/http/{http-types.wit => types.wit} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename wit/deps/http/{http-types.wit => types.wit} (99%) diff --git a/wit/deps/http/incoming-handler.wit b/wit/deps/http/incoming-handler.wit index 25f79806..1ecff0aa 100644 --- a/wit/deps/http/incoming-handler.wit +++ b/wit/deps/http/incoming-handler.wit @@ -7,7 +7,7 @@ // that takes a `request` parameter and returns a `response` result. // default interface incoming-handler { - use pkg.http-types.{incoming-request, response-outparam} + use pkg.types.{incoming-request, response-outparam} // The `handle` function takes an outparam instead of returning its response // so that the component may stream its response while streaming any other diff --git a/wit/deps/http/outgoing-handler.wit b/wit/deps/http/outgoing-handler.wit index 33015b6c..abe812ff 100644 --- a/wit/deps/http/outgoing-handler.wit +++ b/wit/deps/http/outgoing-handler.wit @@ -6,7 +6,7 @@ // that takes a `request` parameter and returns a `response` result. // default interface outgoing-handler { - use pkg.http-types.{outgoing-request, request-options, future-incoming-response} + use pkg.types.{outgoing-request, request-options, future-incoming-response} // The parameter and result types of the `handle` function allow the caller // to concurrently stream the bodies of the outgoing request and the incoming diff --git a/wit/deps/http/http-types.wit b/wit/deps/http/types.wit similarity index 99% rename from wit/deps/http/http-types.wit rename to wit/deps/http/types.wit index 93150d11..bdcf7973 100644 --- a/wit/deps/http/http-types.wit +++ b/wit/deps/http/types.wit @@ -1,7 +1,7 @@ // The `wasi:http/types` interface is meant to be imported by components to // define the HTTP resource types and operations used by the component's // imported and exported interfaces. -default interface http-types { +default interface types { use io.streams.{input-stream, output-stream} use poll.poll.{pollable} From 533894aacdf63bbf55bd172d72941f31bd7e4fee Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:09:06 +0100 Subject: [PATCH 11/16] chore: changes based on review feedback --- host/Cargo.toml | 4 - host/src/default_outgoing_http.rs | 34 +----- host/src/http.rs | 6 +- host/src/http_types.rs | 190 ++++++++++++++++++++++++++++++ host/src/lib.rs | 6 +- 5 files changed, 199 insertions(+), 41 deletions(-) create mode 100644 host/src/http_types.rs diff --git a/host/Cargo.toml b/host/Cargo.toml index a7ba95e9..baa4043f 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -14,13 +14,9 @@ tracing = { workspace = true } wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "8d3a881b524d56498dfc71b65818b2abbeb1da44", features = ["component-model"] } wasi-common = { path = "../wasi-common" } wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" } -reqwest = { version = "0.11.14", optional = true } [dev-dependencies] test-programs-macros = { path = "../test-programs/macros" } tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt" ]} test-log = { version = "0.2", default-features = false, features = ["trace"] } tempfile = "3.3.0" - -[features] -http = ["dep:reqwest"] diff --git a/host/src/default_outgoing_http.rs b/host/src/default_outgoing_http.rs index 4f49462a..3a3d7bcb 100644 --- a/host/src/default_outgoing_http.rs +++ b/host/src/default_outgoing_http.rs @@ -1,42 +1,16 @@ use crate::{ wasi, - wasi::http_types::{ - Error as HttpError, FutureIncomingResponse as Response, Method, OutgoingRequest as Request, - RequestOptions, - }, + wasi::types::{FutureIncomingResponse as Response, OutgoingRequest as Request, RequestOptions}, WasiCtx, }; #[async_trait::async_trait] impl wasi::default_outgoing_http::Host for WasiCtx { - async fn handle<'a>( - &'a mut self, + async fn handle( + &mut self, _req: Request, _options: Option, ) -> wasmtime::Result { - todo!() - } -} - -impl From for HttpError { - fn from(e: reqwest::Error) -> Self { - Self::UnexpectedError(e.to_string()) - } -} - -impl From for reqwest::Method { - fn from(method: Method) -> Self { - match method { - Method::Get => reqwest::Method::GET, - Method::Post => reqwest::Method::POST, - Method::Put => reqwest::Method::PUT, - Method::Delete => reqwest::Method::DELETE, - Method::Patch => reqwest::Method::PATCH, - Method::Connect => reqwest::Method::CONNECT, - Method::Trace => reqwest::Method::TRACE, - Method::Head => reqwest::Method::HEAD, - Method::Options => reqwest::Method::OPTIONS, - _ => panic!("failed due to unsupported method, currently supported methods are: GET, POST, PUT, DELETE, PATCH, CONNECT, TRACE, HEAD, and OPTIONS"), - } + anyhow::bail!("not implemented") } } diff --git a/host/src/http.rs b/host/src/http.rs index 6fe60870..08e91519 100644 --- a/host/src/http.rs +++ b/host/src/http.rs @@ -1,12 +1,12 @@ use crate::{ wasi, - wasi::http_types::{IncomingRequest as Request, ResponseOutparam as Response}, + wasi::types::{IncomingRequest as Request, ResponseOutparam as Response}, WasiCtx, }; #[async_trait::async_trait] impl wasi::http::Host for WasiCtx { - async fn handle<'a>(&'a mut self, _req: Request, _resp: Response) -> anyhow::Result<()> { - todo!() + async fn handle(&mut self, _req: Request, _resp: Response) -> anyhow::Result<()> { + anyhow::bail!("not implemented") } } diff --git a/host/src/http_types.rs b/host/src/http_types.rs new file mode 100644 index 00000000..259e8592 --- /dev/null +++ b/host/src/http_types.rs @@ -0,0 +1,190 @@ +use crate::{ + wasi, + wasi::poll::Pollable, + wasi::types::{ + Error, Fields, FutureIncomingResponse, Headers, IncomingRequest, IncomingResponse, + IncomingStream, Method, OutgoingRequest, OutgoingResponse, OutgoingStream, + ResponseOutparam, Scheme, StatusCode, Trailers, + }, + WasiCtx, +}; + +#[async_trait::async_trait] +impl wasi::types::Host for WasiCtx { + async fn drop_fields(&mut self, _fields: Fields) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn new_fields(&mut self, _entries: Vec<(String, String)>) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn fields_get(&mut self, _fields: Fields, _name: String) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn fields_set( + &mut self, + _fields: Fields, + _name: String, + _value: Vec, + ) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn fields_delete(&mut self, _fields: Fields, _name: String) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn fields_append( + &mut self, + _fields: Fields, + _name: String, + _value: String, + ) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn fields_entries(&mut self, _fields: Fields) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn fields_clone(&mut self, _fields: Fields) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn finish_incoming_stream( + &mut self, + _s: IncomingStream, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn finish_outgoing_stream( + &mut self, + _s: OutgoingStream, + _trailers: Option, + ) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn drop_incoming_request(&mut self, _request: IncomingRequest) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn drop_outgoing_request(&mut self, _request: OutgoingRequest) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn incoming_request_method( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn incoming_request_path( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn incoming_request_scheme( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn incoming_request_authority( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn incoming_request_headers( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn incoming_request_consume( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn incoming_request_query( + &mut self, + _request: IncomingRequest, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn new_outgoing_request( + &mut self, + _method: Method, + _path: String, + _query: String, + _scheme: Option, + _authority: String, + _headers: Headers, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn outgoing_request_write( + &mut self, + _request: OutgoingRequest, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn drop_response_outparam(&mut self, _response: ResponseOutparam) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn set_response_outparam( + &mut self, + _response: Result, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn drop_incoming_response(&mut self, _response: IncomingResponse) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn drop_outgoing_response(&mut self, _response: OutgoingResponse) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn incoming_response_status( + &mut self, + _response: IncomingResponse, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn incoming_response_headers( + &mut self, + _response: IncomingResponse, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn incoming_response_consume( + &mut self, + _response: IncomingResponse, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn new_outgoing_response( + &mut self, + _status_code: StatusCode, + _headers: Headers, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } + async fn outgoing_response_write( + &mut self, + _response: OutgoingResponse, + ) -> wasmtime::Result> { + anyhow::bail!("not implemented") + } + async fn drop_future_incoming_response( + &mut self, + _f: FutureIncomingResponse, + ) -> wasmtime::Result<()> { + anyhow::bail!("not implemented") + } + async fn future_incoming_response_get( + &mut self, + _f: FutureIncomingResponse, + ) -> wasmtime::Result>> { + anyhow::bail!("not implemented") + } + async fn listen_to_future_incoming_response( + &mut self, + _f: FutureIncomingResponse, + ) -> wasmtime::Result { + anyhow::bail!("not implemented") + } +} diff --git a/host/src/lib.rs b/host/src/lib.rs index 64636527..e95523d5 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -1,11 +1,10 @@ mod clocks; -#[cfg(feature = "http")] mod default_outgoing_http; mod env; mod exit; mod filesystem; -#[cfg(feature = "http")] mod http; +mod http_types; mod io; mod ip_name_lookup; mod network; @@ -49,9 +48,8 @@ pub fn add_to_linker( wasi::exit::add_to_linker(l, f)?; wasi::environment::add_to_linker(l, f)?; wasi::environment_preopens::add_to_linker(l, f)?; - #[cfg(feature = "http")] + wasi::types::add_to_linker(l, f)?; wasi::default_outgoing_http::add_to_linker(l, f)?; - #[cfg(feature = "http")] wasi::http::add_to_linker(l, f)?; Ok(()) } From 0933bc42619f39181c63b5ba57cdee53e36c1f1d Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:09:35 +0100 Subject: [PATCH 12/16] chore: add modules to verify --- verify/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/verify/src/main.rs b/verify/src/main.rs index 7241cfec..73bbc644 100644 --- a/verify/src/main.rs +++ b/verify/src/main.rs @@ -45,6 +45,9 @@ fn main() -> Result<()> { && i.module != "environment-preopens" && i.module != "exit" && i.module != "stderr" + && i.module != "types" + && i.module != "incoming-handler" + && i.module != "outgoing-handler" && i.module != "canonical_abi" && i.module != "__main_module__" { From 09b0c8da20d2389c62ac0f89dbc62ccb8411bb26 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:27:46 +0100 Subject: [PATCH 13/16] chore: include features wasi bindings --- wasi/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasi/Cargo.toml b/wasi/Cargo.toml index 55d28162..644a6750 100644 --- a/wasi/Cargo.toml +++ b/wasi/Cargo.toml @@ -6,7 +6,7 @@ edition.workspace = true publish = false [dependencies] -wit-bindgen = { workspace = true, default-features = true } +wit-bindgen = { workspace = true, features = ["macros", "realloc"] } [lib] crate-type = ["lib"] From 7f41229bb4621d8e40137e945d2b705de90141b6 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:28:14 +0100 Subject: [PATCH 14/16] chore: update lock file --- Cargo.lock | 511 ----------------------------------------------------- 1 file changed, 511 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a6c0ceb..f26d2d47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,12 +106,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" - [[package]] name = "camino" version = "1.1.4" @@ -223,22 +217,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - [[package]] name = "cpp_demangle" version = "0.3.5" @@ -524,27 +502,6 @@ dependencies = [ "log", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.1.0" @@ -565,45 +522,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "futures-channel" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" - -[[package]] -name = "futures-sink" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" - -[[package]] -name = "futures-task" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" - -[[package]] -name = "futures-util" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" -dependencies = [ - "futures-core", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "fxhash" version = "0.2.1" @@ -645,25 +563,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "h2" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -711,7 +610,6 @@ dependencies = [ "async-trait", "cap-rand", "cap-std", - "reqwest", "tempfile", "test-log", "test-programs-macros", @@ -724,83 +622,12 @@ dependencies = [ "wasmtime", ] -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "0.14.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "id-arena" version = "2.2.1" @@ -919,15 +746,6 @@ dependencies = [ "libc", ] -[[package]] -name = "js-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -1009,42 +827,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mio" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" -dependencies = [ - "libc", - "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.45.0", -] - -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "num_cpus" version = "1.15.0" @@ -1082,51 +864,6 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" -[[package]] -name = "openssl" -version = "0.10.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "paste" version = "1.0.12" @@ -1145,12 +882,6 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.26" @@ -1318,43 +1049,6 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "reqwest" -version = "0.11.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1383,44 +1077,12 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" -[[package]] -name = "schannel" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" -dependencies = [ - "windows-sys 0.42.0", -] - [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "security-framework" -version = "2.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "1.0.17" @@ -1461,18 +1123,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "sha2" version = "0.10.6" @@ -1493,15 +1143,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "slab" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" -dependencies = [ - "autocfg", -] - [[package]] name = "slice-group-by" version = "0.3.0" @@ -1514,16 +1155,6 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" -[[package]] -name = "socket2" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1668,12 +1299,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" dependencies = [ "autocfg", - "bytes", - "libc", - "memchr", - "mio", "pin-project-lite", - "socket2", "tokio-macros", "windows-sys 0.45.0", ] @@ -1689,30 +1315,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - [[package]] name = "toml" version = "0.5.11" @@ -1722,12 +1324,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - [[package]] name = "tracing" version = "0.1.37" @@ -1776,12 +1372,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - [[package]] name = "typenum" version = "1.16.0" @@ -1847,12 +1437,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "verify" version = "0.1.0" @@ -1868,16 +1452,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1952,72 +1526,6 @@ dependencies = [ "wit-bindgen", ] -[[package]] -name = "wasm-bindgen" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" - [[package]] name = "wasm-encoder" version = "0.24.1" @@ -2321,16 +1829,6 @@ dependencies = [ "wast", ] -[[package]] -name = "web-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "winapi" version = "0.3.9" @@ -2443,15 +1941,6 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "winx" version = "0.35.0" From bce17d18c25d366ae808b8f452a0a64332578910 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:35:44 +0100 Subject: [PATCH 15/16] chore: fix formatting --- host/src/http_types.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/host/src/http_types.rs b/host/src/http_types.rs index 259e8592..681bebb0 100644 --- a/host/src/http_types.rs +++ b/host/src/http_types.rs @@ -17,7 +17,11 @@ impl wasi::types::Host for WasiCtx { async fn new_fields(&mut self, _entries: Vec<(String, String)>) -> wasmtime::Result { anyhow::bail!("not implemented") } - async fn fields_get(&mut self, _fields: Fields, _name: String) -> wasmtime::Result> { + async fn fields_get( + &mut self, + _fields: Fields, + _name: String, + ) -> wasmtime::Result> { anyhow::bail!("not implemented") } async fn fields_set( @@ -123,7 +127,10 @@ impl wasi::types::Host for WasiCtx { ) -> wasmtime::Result> { anyhow::bail!("not implemented") } - async fn drop_response_outparam(&mut self, _response: ResponseOutparam) -> wasmtime::Result<()> { + async fn drop_response_outparam( + &mut self, + _response: ResponseOutparam, + ) -> wasmtime::Result<()> { anyhow::bail!("not implemented") } async fn set_response_outparam( @@ -132,10 +139,16 @@ impl wasi::types::Host for WasiCtx { ) -> wasmtime::Result> { anyhow::bail!("not implemented") } - async fn drop_incoming_response(&mut self, _response: IncomingResponse) -> wasmtime::Result<()> { + async fn drop_incoming_response( + &mut self, + _response: IncomingResponse, + ) -> wasmtime::Result<()> { anyhow::bail!("not implemented") } - async fn drop_outgoing_response(&mut self, _response: OutgoingResponse) -> wasmtime::Result<()> { + async fn drop_outgoing_response( + &mut self, + _response: OutgoingResponse, + ) -> wasmtime::Result<()> { anyhow::bail!("not implemented") } async fn incoming_response_status( From cdac89dfb6deca1fe2ad6e27c4cf8971400d2c3a Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Fri, 17 Mar 2023 15:52:54 +0100 Subject: [PATCH 16/16] chore: fix casing for http imported names --- wit/command.wit | 4 ++-- wit/reactor.wit | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wit/command.wit b/wit/command.wit index 082efd5f..cbdc318e 100644 --- a/wit/command.wit +++ b/wit/command.wit @@ -15,8 +15,8 @@ default world command { import random: random.random import poll: poll.poll import streams: io.streams - import default-outgoing-http: http.outgoing-handler - import http: http.incoming-handler + import default-outgoing-HTTP: http.outgoing-handler + import HTTP: http.incoming-handler import environment: pkg.environment import environment-preopens: pkg.environment-preopens import exit: pkg.exit diff --git a/wit/reactor.wit b/wit/reactor.wit index fdc22912..5ce3cfc5 100644 --- a/wit/reactor.wit +++ b/wit/reactor.wit @@ -15,8 +15,8 @@ default world reactor { import random: random.random import poll: poll.poll import streams: io.streams - import default-outgoing-http: http.outgoing-handler - import http: http.incoming-handler + import default-outgoing-HTTP: http.outgoing-handler + import HTTP: http.incoming-handler import environment: pkg.environment import environment-preopens: pkg.environment-preopens import exit: pkg.exit