1 mod bindings {
2 wit_bindgen::generate!({
3 path: "../wasi-http/src/p3/wit",
4 world: "local:local/middleware-with-chain",
5 inline: "
6 package local:local;
7
8 world middleware-with-chain {
9 include wasi:http/service@0.3.0-rc-2026-03-15;
10
11 import chain-http;
12 }
13
14 interface chain-http {
15 use wasi:http/types@0.3.0-rc-2026-03-15.{request, response, error-code};
16
17 handle: async func(request: request) -> result<response, error-code>;
18 }
19 ",
20 // workaround https://github.com/bytecodealliance/wit-bindgen/issues/1544
21 // generate_all
22 with: {
23 "wasi:http/types@0.3.0-rc-2026-03-15": test_programs::p3::wasi::http::types,
24 "wasi:http/client@0.3.0-rc-2026-03-15": test_programs::p3::wasi::http::client,
25 "wasi:random/random@0.3.0-rc-2026-03-15": test_programs::p3::wasi::random::random,
26 "wasi:random/insecure@0.3.0-rc-2026-03-15": test_programs::p3::wasi::random::insecure,
27 "wasi:random/insecure-seed@0.3.0-rc-2026-03-15": test_programs::p3::wasi::random::insecure_seed,
28 "wasi:cli/stdout@0.3.0-rc-2026-03-15": test_programs::p3::wasi::cli::stdout,
29 "wasi:cli/stderr@0.3.0-rc-2026-03-15": test_programs::p3::wasi::cli::stderr,
30 "wasi:cli/stdin@0.3.0-rc-2026-03-15": test_programs::p3::wasi::cli::stdin,
31 "wasi:cli/types@0.3.0-rc-2026-03-15": test_programs::p3::wasi::cli::types,
32 "wasi:clocks/monotonic-clock@0.3.0-rc-2026-03-15": test_programs::p3::wasi::clocks::monotonic_clock,
33 "wasi:clocks/system-clock@0.3.0-rc-2026-03-15": test_programs::p3::wasi::clocks::system_clock,
34 "wasi:clocks/types@0.3.0-rc-2026-03-15": test_programs::p3::wasi::clocks::types,
35 },
36 });
37
38 use super::Component;
39 export!(Component);
40 }
41
42 use bindings::{exports::wasi::http::handler::Guest as Handler, local::local::chain_http};
43 use std::time::Duration;
44 use test_programs::p3::wasi::clocks::monotonic_clock;
45 use test_programs::p3::wasi::http::types::{ErrorCode, Request, Response};
46
47 struct Component;
48
49 impl Handler for Component {
handle(request: Request) -> Result<Response, ErrorCode>50 async fn handle(request: Request) -> Result<Response, ErrorCode> {
51 // First, sleep briefly. This will ensure the next call happens via a
52 // host->guest call to the `wit_bindgen_rt::async_support::callback`
53 // function, which exercises different code paths in both the host and
54 // the guest, which we want to test here.
55 let duration = Duration::from_millis(10);
56 monotonic_clock::wait_for(duration.as_nanos().try_into().unwrap()).await;
57
58 chain_http::handle(request).await
59 }
60 }
61
62 // Unused function; required since this file is built as a `bin`:
main()63 fn main() {}
64