Skip to content

Commit 1856252

Browse files
authored
Merge pull request #1901 from fermyon/no-more-http
No more http and `inbound-http` interfaces
2 parents 12becdc + 72ba8ae commit 1856252

File tree

60 files changed

+891
-1021
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+891
-1021
lines changed

Cargo.lock

Lines changed: 75 additions & 140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ members = ["crates/*", "sdk/rust", "sdk/rust/macro"]
111111
[workspace.dependencies]
112112
anyhow = "1.0.75"
113113
tracing = { version = "0.1", features = ["log"] }
114-
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", rev = "c796ce7376a57a40605f03e74bd78cefcc9acf3a", features = [
114+
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2da78ca5c4c1e5a8cbc88a8ad3accf24bb4e6cfb", features = [
115115
"tokio",
116116
] }
117-
wasi-common-preview1 = { git = "https://github.com/bytecodealliance/wasmtime", rev = "c796ce7376a57a40605f03e74bd78cefcc9acf3a", package = "wasi-common" }
118-
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "c796ce7376a57a40605f03e74bd78cefcc9acf3a", features = [
117+
wasi-common-preview1 = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2da78ca5c4c1e5a8cbc88a8ad3accf24bb4e6cfb", package = "wasi-common" }
118+
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2da78ca5c4c1e5a8cbc88a8ad3accf24bb4e6cfb", features = [
119119
"component-model",
120120
] }
121-
wasmtime-wasi-http = { git = "https://github.com/bytecodealliance/wasmtime", rev = "c796ce7376a57a40605f03e74bd78cefcc9acf3a" }
122-
spin-componentize = { git = "https://github.com/fermyon/spin-componentize", rev = "00820a455086c3d04b1a01236af03be38aac38a1" }
121+
wasmtime-wasi-http = { git = "https://github.com/bytecodealliance/wasmtime", rev = "2da78ca5c4c1e5a8cbc88a8ad3accf24bb4e6cfb" }
122+
spin-componentize = { git = "https://github.com/fermyon/spin-componentize", rev = "191789170abde10cd55590466c0660dd6c7d472a" }
123123
hyper = { version = "=1.0.0-rc.3", features = ["full"] }
124124
http-body-util = "=0.1.0-rc.2"
125125

crates/core/src/lib.rs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crossbeam_channel::Sender;
2020
use tracing::instrument;
2121
use wasmtime::{InstanceAllocationStrategy, PoolingAllocationConfig};
2222
use wasmtime_wasi::preview2::Table;
23-
use wasmtime_wasi_http::types::{WasiHttpCtx, WasiHttpView};
23+
use wasmtime_wasi_http::types::{default_send_request, WasiHttpCtx, WasiHttpView};
2424

2525
use self::host_component::{HostComponents, HostComponentsBuilder};
2626

@@ -191,7 +191,7 @@ impl<T: Send> wasmtime_wasi::preview2::WasiView for Data<T> {
191191
}
192192
}
193193

194-
impl<T: Send> WasiHttpView for Data<T> {
194+
impl<T: Send + OutboundWasiHttpHandler> WasiHttpView for Data<T> {
195195
fn ctx(&mut self) -> &mut WasiHttpCtx {
196196
match &mut self.wasi {
197197
Wasi::Preview1(_) => panic!("using WASI Preview 1 functions with Preview 2 store"),
@@ -202,6 +202,45 @@ impl<T: Send> WasiHttpView for Data<T> {
202202
fn table(&mut self) -> &mut Table {
203203
&mut self.table
204204
}
205+
206+
fn send_request(
207+
&mut self,
208+
request: wasmtime_wasi_http::types::OutgoingRequest,
209+
) -> wasmtime::Result<
210+
wasmtime::component::Resource<wasmtime_wasi_http::types::HostFutureIncomingResponse>,
211+
>
212+
where
213+
Self: Sized,
214+
{
215+
T::send_request(self, request)
216+
}
217+
}
218+
219+
/// Handler for wasi-http based requests
220+
pub trait OutboundWasiHttpHandler {
221+
/// Send the request
222+
fn send_request(
223+
data: &mut Data<Self>,
224+
request: wasmtime_wasi_http::types::OutgoingRequest,
225+
) -> wasmtime::Result<
226+
wasmtime::component::Resource<wasmtime_wasi_http::types::HostFutureIncomingResponse>,
227+
>
228+
where
229+
Self: Sized;
230+
}
231+
232+
impl OutboundWasiHttpHandler for () {
233+
fn send_request(
234+
data: &mut Data<Self>,
235+
request: wasmtime_wasi_http::types::OutgoingRequest,
236+
) -> wasmtime::Result<
237+
wasmtime::component::Resource<wasmtime_wasi_http::types::HostFutureIncomingResponse>,
238+
>
239+
where
240+
Self: Sized,
241+
{
242+
default_send_request(data, request)
243+
}
205244
}
206245

207246
/// An alias for [`wasmtime::Linker`] specialized to [`Data`].
@@ -222,13 +261,10 @@ pub struct EngineBuilder<T> {
222261
epoch_ticker_thread: bool,
223262
}
224263

225-
impl<T: Send + Sync> EngineBuilder<T> {
264+
impl<T: Send + Sync + OutboundWasiHttpHandler> EngineBuilder<T> {
226265
fn new(config: &Config) -> Result<Self> {
227266
let engine = wasmtime::Engine::new(&config.inner)?;
228-
229-
let mut linker: Linker<T> = Linker::new(&engine);
230-
wasmtime_wasi_http::proxy::add_to_linker(&mut linker)?;
231-
267+
let linker: Linker<T> = Linker::new(&engine);
232268
let mut module_linker = ModuleLinker::new(&engine);
233269
wasmtime_wasi::tokio::add_to_linker(&mut module_linker, |data| match &mut data.wasi {
234270
Wasi::Preview1(ctx) => ctx,
@@ -244,7 +280,9 @@ impl<T: Send + Sync> EngineBuilder<T> {
244280
epoch_ticker_thread: true,
245281
})
246282
}
283+
}
247284

285+
impl<T: Send + Sync> EngineBuilder<T> {
248286
/// Adds definition(s) to the built [`Engine`].
249287
///
250288
/// This method's signature is meant to be used with
@@ -345,7 +383,7 @@ pub struct Engine<T> {
345383
_epoch_ticker_signal: Option<Sender<()>>,
346384
}
347385

348-
impl<T: Send + Sync> Engine<T> {
386+
impl<T: OutboundWasiHttpHandler + Send + Sync> Engine<T> {
349387
/// Creates a new [`EngineBuilder`] with the given [`Config`].
350388
pub fn builder(config: &Config) -> Result<EngineBuilder<T>> {
351389
EngineBuilder::new(config)

crates/core/tests/integration_test.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ fn test_config() -> Config {
178178
fn test_engine() -> Engine<()> {
179179
let mut builder = Engine::builder(&test_config()).unwrap();
180180
builder.add_host_component(MultiplierHostComponent).unwrap();
181+
builder
182+
.link_import(|l, _| wasmtime_wasi::preview2::command::add_to_linker(l))
183+
.unwrap();
181184
builder.build()
182185
}
183186

@@ -212,8 +215,8 @@ async fn run_core_wasi_test_engine<'a>(
212215
let mut exports = instance.exports(&mut store);
213216

214217
let mut instance = exports
215-
.instance("wasi:cli/run")
216-
.context("missing the expected 'wasi:cli/run' instance")?;
218+
.instance("wasi:cli/run@0.2.0-rc-2023-10-18")
219+
.context("missing the expected 'wasi:cli/run@0.2.0-rc-2023-10-18' instance")?;
217220
instance.typed_func::<(), (Result<(), ()>,)>("run")?
218221
};
219222
update_store(&mut store);

crates/http/src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ pub struct HttpTriggerConfig {
2121
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
2222
#[serde(deny_unknown_fields, rename_all = "lowercase", tag = "type")]
2323
pub enum HttpExecutorType {
24-
/// The component implements the Spin HTTP interface.
24+
/// The component implements an HTTP based interface.
25+
///
26+
/// This can be either `fermyon:spin/inbound-http` or `wasi:http/incoming-handler`
2527
#[default]
26-
Spin,
28+
#[serde(alias = "spin")]
29+
Http,
2730
/// The component implements the Wagi CGI interface.
2831
Wagi(WagiTriggerConfig),
29-
/// The component implements [`wasi-http`](https://github.com/WebAssembly/wasi-http)
30-
/// interface (experimental, subject to change)
31-
Wasi,
3232
}
3333

3434
/// Wagi specific configuration for the http executor.

crates/loader/tests/triggers/http.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
description = "A dummy manifest for testing parsing."
44
name = "spin-hello-world"
5-
trigger = {type = "http", base = "/test"}
5+
trigger = { type = "http", base = "/test" }
66
version = "1.0.0"
77

88
[variables]
@@ -13,6 +13,7 @@ id = "http-spin"
1313
source = "dummy.wasm.txt"
1414
[component.trigger]
1515
route = "/hello/..."
16+
executor = { type = "wagi" }
1617
[component.config]
1718
message = "I'm a {{object}}"
1819

@@ -21,6 +22,6 @@ id = "http-wagi"
2122
source = "dummy.wasm.txt"
2223
[component.trigger]
2324
route = "/waggy/..."
24-
executor = { type = "wagi" }
25+
executor = { type = "wagi" }
2526
[component.config]
2627
message = "I'm a {{object}}"

crates/loader/tests/ui/valid-manifest.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"trigger_config": {
2525
"component": "four-lights",
2626
"executor": {
27-
"type": "spin"
27+
"type": "http"
2828
},
2929
"route": "/lights"
3030
}

crates/loader/tests/ui/valid-manifest.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ spin_version = "1"
22
authors = ["Gul Madred", "Edward Jellico", "JL"]
33
description = "A simple application that returns the number of lights"
44
name = "chain-of-command"
5-
trigger = {type = "http"}
5+
trigger = { type = "http" }
66
version = "6.11.2"
77

88
[[component]]
99
id = "four-lights"
1010
source = "wasm/dummy.wasm"
1111
[component.trigger]
12-
executor = {type = "spin"}
12+
executor = { type = "http" }
1313
route = "/lights"
1414
[component.environment]
1515
env1 = "first"

crates/loader/tests/ui/valid-with-files/spin.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"trigger_config": {
2222
"component": "fs",
2323
"executor": {
24-
"type": "spin"
24+
"type": "http"
2525
},
2626
"route": "/..."
2727
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
name = "spin-local-source-test"
4-
trigger = {type = "http"}
4+
trigger = { type = "http" }
55
version = "1.0.0"
66

77
[[component]]
@@ -10,5 +10,5 @@ id = "fs"
1010
source = "spin-fs.wasm"
1111

1212
[component.trigger]
13-
executor = {type = "spin"}
13+
executor = { type = "http" }
1414
route = "/..."

0 commit comments

Comments
 (0)