Skip to content

Commit e035f4f

Browse files
committed
Migrate spin-http to new core
Signed-off-by: Lann Martin <lann.martin@fermyon.com>
1 parent 7ab0388 commit e035f4f

File tree

15 files changed

+341
-297
lines changed

15 files changed

+341
-297
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ spin-publish = { path = "crates/publish" }
4040
spin-redis-engine = { path = "crates/redis" }
4141
spin-templates = { path = "crates/templates" }
4242
spin-trigger = { path = "crates/trigger" }
43+
spin-trigger-new = { path = "crates/trigger-new" }
4344
tempfile = "3.3.0"
4445
tokio = { version = "1.11", features = [ "full" ] }
4546
toml = "0.5"

crates/app/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,17 @@ impl<'a> App<'a> {
110110
&self.uri
111111
}
112112

113-
pub fn get_metadata<'this, T: Deserialize<'this>>(&'this self, key: &str) -> Option<Result<T>> {
113+
pub fn get_metadata<'this, T: Deserialize<'this>>(&'this self, key: &str) -> Result<Option<T>> {
114114
self.locked
115115
.metadata
116116
.get(key)
117117
.map(|value| Ok(T::deserialize(value)?))
118+
.transpose()
118119
}
119120

120121
pub fn require_metadata<'this, T: Deserialize<'this>>(&'this self, key: &str) -> Result<T> {
121-
self.get_metadata(key)
122-
.ok_or_else(|| Error::ManifestError(format!("missing required {key:?}")))?
122+
self.get_metadata(key)?
123+
.ok_or_else(|| Error::ManifestError(format!("missing required {key:?}")))
123124
}
124125

125126
pub fn variables(&self) -> impl Iterator<Item = (&String, &Variable)> {
@@ -169,11 +170,18 @@ impl<'a> AppComponent<'a> {
169170
self.locked.files.iter()
170171
}
171172

172-
pub fn get_metadata<T: Deserialize<'a>>(&self, key: &str) -> Option<Result<T>> {
173+
pub fn get_metadata<T: Deserialize<'a>>(&self, key: &str) -> Result<Option<T>> {
173174
self.locked
174175
.metadata
175176
.get(key)
176-
.map(|value| Ok(T::deserialize(value)?))
177+
.map(|value| {
178+
T::deserialize(value).map_err(|err| {
179+
Error::ManifestError(format!(
180+
"failed to deserialize {key:?} = {value:?}: {err:?}"
181+
))
182+
})
183+
})
184+
.transpose()
177185
}
178186

179187
pub fn config(&self) -> impl Iterator<Item = (&String, &String)> {

crates/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use anyhow::Result;
99
use tracing::instrument;
1010
use wasmtime_wasi::WasiCtx;
1111

12-
pub use wasmtime::{self, Instance, Module};
12+
pub use wasmtime::{self, Instance, Module, Trap};
1313

1414
use self::host_component::{HostComponents, HostComponentsBuilder};
1515

crates/http/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ http = "0.2"
1717
hyper = { version = "0.14", features = ["full"] }
1818
indexmap = "1"
1919
percent-encoding = "2"
20-
spin-manifest = { path = "../manifest" }
21-
spin-engine = { path = "../engine" }
22-
spin-trigger = { path = "../trigger" }
20+
rustls-pemfile = "0.3.0"
21+
serde = { version = "1.0", features = ["derive"] }
22+
spin-app = { path = "../app" }
23+
spin-core = { path = "../core" }
24+
spin-trigger-new = { path = "../trigger-new" }
2325
tls-listener = { version = "0.4.0", features = [
2426
"rustls",
2527
"hyper-h1",
2628
"hyper-h2",
2729
] }
2830
tokio = { version = "1.10", features = ["full"] }
2931
tokio-rustls = { version = "0.23.2" }
30-
rustls-pemfile = "0.3.0"
3132
tracing = { version = "0.1", features = ["log"] }
32-
wasi-common = "0.39.1"
33-
wasmtime = { version = "0.39.1", features = ["async"] }
3433

3534
[dependencies.wit-bindgen-wasmtime]
3635
git = "https://github.com/bytecodealliance/wit-bindgen"
@@ -39,8 +38,8 @@ features = ["async"]
3938

4039
[dev-dependencies]
4140
criterion = { version = "0.3.5", features = ["async_tokio"] }
42-
miniserde = "0.1"
4341
num_cpus = "1"
42+
serde_json = "1"
4443
spin-testing = { path = "../testing" }
4544

4645
[[bench]]

crates/http/benches/baseline.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use futures::future::join_all;
77
use http::uri::Scheme;
88
use http::Request;
99
use spin_http::HttpTrigger;
10-
use spin_manifest::{HttpConfig, HttpExecutor};
1110
use spin_testing::{assert_http_response_success, TestConfig};
1211
use tokio::runtime::Runtime;
1312
use tokio::task;
@@ -29,7 +28,7 @@ fn bench_startup(c: &mut Criterion) {
2928
b.to_async(&async_runtime).iter(|| async {
3029
let trigger = TestConfig::default()
3130
.test_program("spin-http-benchmark.wasm")
32-
.http_trigger(Default::default())
31+
.http_spin_trigger("/")
3332
.build_http_trigger()
3433
.await;
3534
run_concurrent_requests(Arc::new(trigger), 0, 1).await;
@@ -39,10 +38,7 @@ fn bench_startup(c: &mut Criterion) {
3938
b.to_async(&async_runtime).iter(|| async {
4039
let trigger = TestConfig::default()
4140
.test_program("wagi-benchmark.wasm")
42-
.http_trigger(HttpConfig {
43-
executor: Some(HttpExecutor::Wagi(Default::default())),
44-
..Default::default()
45-
})
41+
.http_wagi_trigger("/", Default::default())
4642
.build_http_trigger()
4743
.await;
4844
run_concurrent_requests(Arc::new(trigger), 0, 1).await;
@@ -58,7 +54,7 @@ fn bench_spin_concurrency_minimal(c: &mut Criterion) {
5854
async_runtime.block_on(
5955
TestConfig::default()
6056
.test_program("spin-http-benchmark.wasm")
61-
.http_trigger(Default::default())
57+
.http_spin_trigger("/")
6258
.build_http_trigger(),
6359
),
6460
);
@@ -94,10 +90,7 @@ fn bench_wagi_concurrency_minimal(c: &mut Criterion) {
9490
async_runtime.block_on(
9591
TestConfig::default()
9692
.test_program("wagi-benchmark.wasm")
97-
.http_trigger(HttpConfig {
98-
executor: Some(HttpExecutor::Wagi(Default::default())),
99-
..Default::default()
100-
})
93+
.http_wagi_trigger("/", Default::default())
10194
.build_http_trigger(),
10295
),
10396
);

0 commit comments

Comments
 (0)