Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/vendor-wit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ get_github() {
}

p2=0.2.6
p3=0.3.0-rc-2025-09-16
p3=0.3.0-rc-2026-01-06

rm -rf crates/wasi-io/wit/deps
mkdir -p crates/wasi-io/wit/deps
Expand Down
6 changes: 3 additions & 3 deletions crates/test-programs/src/bin/p3_api_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use wit_bindgen::spawn;

struct T;

test_programs::p3::proxy::export!(T);
test_programs::p3::service::export!(T);

impl test_programs::p3::proxy::exports::wasi::http::handler::Guest for T {
impl test_programs::p3::service::exports::wasi::http::handler::Guest for T {
async fn handle(request: Request) -> Result<Response, ErrorCode> {
assert!(request.get_scheme().is_some());
assert!(request.get_authority().is_some());
Expand Down Expand Up @@ -54,7 +54,7 @@ impl test_programs::p3::proxy::exports::wasi::http::handler::Guest for T {
}
}

// Technically this should not be here for a proxy, but given the current
// Technically this should not be here for a service, but given the current
// framework for tests it's required since this file is built as a `bin`
fn main() {}

Expand Down
6 changes: 3 additions & 3 deletions crates/test-programs/src/bin/p3_cli_serve_hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use test_programs::p3::wasi::http::types::{ErrorCode, Fields, Request, Response};
use test_programs::p3::{proxy, wit_future, wit_stream};
use test_programs::p3::{service, wit_future, wit_stream};

struct T;

proxy::export!(T);
service::export!(T);

impl proxy::exports::wasi::http::handler::Guest for T {
impl service::exports::wasi::http::handler::Guest for T {
async fn handle(_request: Request) -> Result<Response, ErrorCode> {
let (mut body_tx, body_rx) = wit_stream::new();
let (body_result_tx, body_result_rx) = wit_future::new(|| Ok(None));
Expand Down
6 changes: 3 additions & 3 deletions crates/test-programs/src/bin/p3_cli_serve_sleep.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use test_programs::p3::proxy;
use test_programs::p3::service;
use test_programs::p3::wasi::clocks::monotonic_clock;
use test_programs::p3::wasi::http::types::{ErrorCode, Request, Response};

struct T;

proxy::export!(T);
service::export!(T);

impl proxy::exports::wasi::http::handler::Guest for T {
impl service::exports::wasi::http::handler::Guest for T {
async fn handle(_request: Request) -> Result<Response, ErrorCode> {
monotonic_clock::wait_for(u64::MAX).await;
unreachable!()
Expand Down
4 changes: 2 additions & 2 deletions crates/test-programs/src/bin/p3_http_echo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
test_programs::p3::{
proxy::exports::wasi::http::handler::Guest as Handler,
service::exports::wasi::http::handler::Guest as Handler,
wasi::http::types::{ErrorCode, Request, Response},
wit_future, wit_stream,
},
Expand All @@ -9,7 +9,7 @@ use {

struct Component;

test_programs::p3::proxy::export!(Component);
test_programs::p3::service::export!(Component);

impl Handler for Component {
/// Return a response which echoes the request headers, body, and trailers.
Expand Down
25 changes: 22 additions & 3 deletions crates/test-programs/src/bin/p3_http_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use {
},
std::{io::Write, mem},
test_programs::p3::{
proxy::exports::wasi::http::handler::Guest as Handler,
wasi::http::{
handler,
types::{ErrorCode, Headers, Request, Response},
Expand All @@ -15,11 +14,31 @@ use {
wit_bindgen::StreamResult,
};

wit_bindgen::generate!({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for generating the bindings locally here? I.e. what changed such that using the bindings generated in test_programs/src/p3/mod.rs is no longer feasible?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I tried that initially but it's a wit-bindgen bug. The way the exported macros are generated, namespaced, etc, means that you can't generate, even in separate modules in the same crate, two worlds where the worlds overlap in exports. The middleware/service worlds overlap in their export of wasi:http/handler meaning that putting the two in the same crate would clash. I'll file a bug over on the wit-bindgen side of things for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, this issue

path: "../wasi-http/src/p3/wit",
world: "wasi:http/middleware",
with: {
"wasi:http/handler@0.3.0-rc-2026-01-06": test_programs::p3::wasi::http::handler,
"wasi:http/types@0.3.0-rc-2026-01-06": test_programs::p3::wasi::http::types,
"wasi:http/client@0.3.0-rc-2026-01-06": test_programs::p3::wasi::http::client,
"wasi:random/random@0.3.0-rc-2026-01-06": test_programs::p3::wasi::random::random,
"wasi:random/insecure@0.3.0-rc-2026-01-06": test_programs::p3::wasi::random::insecure,
"wasi:random/insecure-seed@0.3.0-rc-2026-01-06": test_programs::p3::wasi::random::insecure_seed,
"wasi:cli/stdout@0.3.0-rc-2026-01-06": test_programs::p3::wasi::cli::stdout,
"wasi:cli/stderr@0.3.0-rc-2026-01-06": test_programs::p3::wasi::cli::stderr,
"wasi:cli/stdin@0.3.0-rc-2026-01-06": test_programs::p3::wasi::cli::stdin,
"wasi:cli/types@0.3.0-rc-2026-01-06": test_programs::p3::wasi::cli::types,
"wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06": test_programs::p3::wasi::clocks::monotonic_clock,
"wasi:clocks/system-clock@0.3.0-rc-2026-01-06": test_programs::p3::wasi::clocks::system_clock,
"wasi:clocks/types@0.3.0-rc-2026-01-06": test_programs::p3::wasi::clocks::types,
},
});

struct Component;

test_programs::p3::proxy::export!(Component);
export!(Component);

impl Handler for Component {
impl exports::wasi::http::handler::Guest for Component {
/// Forward the specified request to the imported `wasi:http/handler`, transparently decoding the request body
/// if it is `deflate`d and then encoding the response body if the client has provided an `accept-encoding:
/// deflate` header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ mod bindings {
package local:local;
world middleware-with-chain {
include wasi:http/proxy@0.3.0-rc-2025-09-16;
include wasi:http/service@0.3.0-rc-2026-01-06;
import chain-http;
}
interface chain-http {
use wasi:http/types@0.3.0-rc-2025-09-16.{request, response, error-code};
use wasi:http/types@0.3.0-rc-2026-01-06.{request, response, error-code};
handle: async func(request: request) -> result<response, error-code>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use futures::join;
use test_programs::p3::wasi::http::handler;
use test_programs::p3::wasi::http::client;
use test_programs::p3::wasi::http::types::{ErrorCode, Headers, Method, Request, Scheme, Trailers};
use test_programs::p3::{wit_future, wit_stream};
use wit_bindgen::{FutureReader, FutureWriter, StreamWriter};
Expand Down Expand Up @@ -47,7 +47,7 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
{
let (request, mut contents_tx, trailers_tx, transmit) = make_request();
let (handle, transmit, ()) = join!(
async { handler::handle(request).await },
async { client::send(request).await },
async { transmit.await },
async {
let remaining = contents_tx.write_all(b"long enough".to_vec()).await;
Expand All @@ -64,7 +64,7 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
{
let (request, mut contents_tx, trailers_tx, transmit) = make_request();
let (handle, transmit, ()) = join!(
async { handler::handle(request).await },
async { client::send(request).await },
async { transmit.await },
async {
let remaining = contents_tx.write_all(b"msg".to_vec()).await;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
{
let (request, mut contents_tx, trailers_tx, transmit) = make_request();
let (handle, transmit, ()) = join!(
async { handler::handle(request).await },
async { client::send(request).await },
async { transmit.await },
async {
let remaining = contents_tx.write_all(b"more than 11 bytes".to_vec()).await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test_programs::p3::wasi::http::handler::handle;
use test_programs::p3::wasi::http::client::send;
use test_programs::p3::wasi::http::types::{Fields, Method, Request, Scheme};
use test_programs::p3::wit_future;

Expand All @@ -18,7 +18,7 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
// Don't set path/query
// req.set_path_with_query(Some("/")).unwrap();

let res = handle(req).await;
let res = send(req).await;
assert!(res.is_err());
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/test-programs/src/bin/p3_http_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use {
test_programs::p3::{
proxy::exports::wasi::http::handler::Guest as Handler,
service::exports::wasi::http::handler::Guest as Handler,
wasi::http::{
handler,
client,
types::{ErrorCode, Fields, Request, Response, Scheme},
},
wit_future,
Expand All @@ -12,7 +12,7 @@ use {

struct Component;

test_programs::p3::proxy::export!(Component);
test_programs::p3::service::export!(Component);

impl Handler for Component {
// Forward the request body and trailers to a URL specified in a header.
Expand Down Expand Up @@ -42,7 +42,7 @@ impl Handler for Component {
outgoing_request
.set_authority(Some(url.authority()))
.unwrap();
handler::handle(outgoing_request).await?
client::send(outgoing_request).await?
} else {
bad_request()
},
Expand Down
4 changes: 2 additions & 2 deletions crates/test-programs/src/p3/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{Context as _, Result, anyhow};
use core::fmt;
use futures::join;

use crate::p3::wasi::http::{handler, types};
use crate::p3::wasi::http::{client, types};
use crate::p3::{wit_future, wit_stream};

pub struct Response {
Expand Down Expand Up @@ -91,7 +91,7 @@ pub async fn request(
let (transmit, handle) = join!(
async { transmit.await.context("failed to transmit request") },
async {
let response = handler::handle(request).await?;
let response = client::send(request).await?;
let status = response.get_status_code();
let headers = response.get_headers().copy_all();
let (_, result_rx) = wit_future::new(|| Ok(()));
Expand Down
44 changes: 21 additions & 23 deletions crates/test-programs/src/p3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ wit_bindgen::generate!({
package wasmtime:test;

world testp3 {
include wasi:cli/imports@0.3.0-rc-2025-09-16;
include wasi:http/imports@0.3.0-rc-2025-09-16;
include wasi:cli/imports@0.3.0-rc-2026-01-06;
import wasi:http/types@0.3.0-rc-2026-01-06;
import wasi:http/client@0.3.0-rc-2026-01-06;
import wasi:http/handler@0.3.0-rc-2026-01-06;

export wasi:cli/run@0.3.0-rc-2025-09-16;
export wasi:cli/run@0.3.0-rc-2026-01-06;
}
",
path: "../wasi-http/src/p3/wit",
Expand All @@ -19,30 +21,26 @@ wit_bindgen::generate!({
generate_all,
});

pub mod proxy {
pub mod service {
wit_bindgen::generate!({
inline: "
package wasmtime:test;

world proxyp3 {
include wasi:http/proxy@0.3.0-rc-2025-09-16;
}
",
path: "../wasi-http/src/p3/wit",
world: "wasmtime:test/proxyp3",
default_bindings_module: "test_programs::p3::proxy",
world: "wasi:http/service",
default_bindings_module: "test_programs::p3::service",
pub_export_macro: true,
with: {
"wasi:http/handler@0.3.0-rc-2025-09-16": generate,
"wasi:http/types@0.3.0-rc-2025-09-16": crate::p3::wasi::http::types,
"wasi:random/random@0.3.0-rc-2025-09-16": crate::p3::wasi::random::random,
"wasi:cli/stdout@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::stdout,
"wasi:cli/stderr@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::stderr,
"wasi:cli/stdin@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::stdin,
"wasi:cli/types@0.3.0-rc-2025-09-16": crate::p3::wasi::cli::types,
"wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16": crate::p3::wasi::clocks::monotonic_clock,
"wasi:clocks/wall-clock@0.3.0-rc-2025-09-16": crate::p3::wasi::clocks::wall_clock,
"wasi:clocks/types@0.3.0-rc-2025-09-16": crate::p3::wasi::clocks::types,
"wasi:http/handler@0.3.0-rc-2026-01-06": crate::p3::wasi::http::handler,
"wasi:http/types@0.3.0-rc-2026-01-06": crate::p3::wasi::http::types,
"wasi:http/client@0.3.0-rc-2026-01-06": crate::p3::wasi::http::client,
"wasi:random/random@0.3.0-rc-2026-01-06": crate::p3::wasi::random::random,
"wasi:random/insecure@0.3.0-rc-2026-01-06": crate::p3::wasi::random::insecure,
"wasi:random/insecure-seed@0.3.0-rc-2026-01-06": crate::p3::wasi::random::insecure_seed,
"wasi:cli/stdout@0.3.0-rc-2026-01-06": crate::p3::wasi::cli::stdout,
"wasi:cli/stderr@0.3.0-rc-2026-01-06": crate::p3::wasi::cli::stderr,
"wasi:cli/stdin@0.3.0-rc-2026-01-06": crate::p3::wasi::cli::stdin,
"wasi:cli/types@0.3.0-rc-2026-01-06": crate::p3::wasi::cli::types,
"wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06": crate::p3::wasi::clocks::monotonic_clock,
"wasi:clocks/system-clock@0.3.0-rc-2026-01-06": crate::p3::wasi::clocks::system_clock,
"wasi:clocks/types@0.3.0-rc-2026-01-06": crate::p3::wasi::clocks::types,
},
});
}
4 changes: 2 additions & 2 deletions crates/wasi-http/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum ProxyPre<T: 'static> {
P2(p2::bindings::ProxyPre<T>),
/// A `wasi:http/handler@0.3.x` pre-instance.
#[cfg(feature = "p3")]
P3(p3::bindings::ProxyPre<T>),
P3(p3::bindings::ServicePre<T>),
}

impl<T: 'static> ProxyPre<T> {
Expand All @@ -75,7 +75,7 @@ pub enum Proxy {
P2(p2::bindings::Proxy),
/// A `wasi:http/handler@0.3.x` instance.
#[cfg(feature = "p3")]
P3(p3::bindings::Proxy),
P3(p3::bindings::Service),
}

/// Represents a task to run using a `wasi:http/incoming-handler@0.2.x` or
Expand Down
10 changes: 5 additions & 5 deletions crates/wasi-http/src/p3/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
mod generated {
wasmtime::component::bindgen!({
path: "src/p3/wit",
world: "wasi:http/proxy",
world: "wasi:http/service",
imports: {
"wasi:http/handler.handle": store | trappable | tracing,
"wasi:http/client.send": store | trappable | tracing,
"wasi:http/types.[drop]request": store | trappable | tracing,
"wasi:http/types.[drop]response": store | trappable | tracing,
"wasi:http/types.[static]request.consume-body": store | trappable | tracing,
Expand Down Expand Up @@ -37,8 +37,8 @@ mod generated {

pub use self::generated::wasi::*;

/// Raw bindings to the `wasi:http/proxy` exports.
/// Raw bindings to the `wasi:http/service` exports.
pub use self::generated::exports;

/// Bindings to the `wasi:http/proxy` world.
pub use self::generated::{Proxy, ProxyIndices, ProxyPre};
/// Bindings to the `wasi:http/service` world.
pub use self::generated::{Service, ServiceIndices, ServicePre};
4 changes: 2 additions & 2 deletions crates/wasi-http/src/p3/host/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::p3::bindings::http::handler::{Host, HostWithStore};
use crate::p3::bindings::http::client::{Host, HostWithStore};
use crate::p3::bindings::http::types::{ErrorCode, Request, Response};
use crate::p3::body::{Body, BodyExt as _};
use crate::p3::{HttpError, HttpResult, WasiHttp, WasiHttpCtxView};
Expand Down Expand Up @@ -34,7 +34,7 @@ async fn io_task_result(
}

impl HostWithStore for WasiHttp {
async fn handle<T>(
async fn send<T>(
store: &Accessor<T, Self>,
req: Resource<Request>,
) -> HttpResult<Resource<Response>> {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/src/p3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use response::Response;

use crate::p3::bindings::http::types::ErrorCode;
use crate::types::DEFAULT_FORBIDDEN_HEADERS;
use bindings::http::{handler, types};
use bindings::http::{client, types};
use bytes::Bytes;
use core::ops::Deref;
use http::HeaderName;
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn add_to_linker<T>(linker: &mut Linker<T>) -> wasmtime::Result<()>
where
T: WasiHttpView + 'static,
{
handler::add_to_linker::<_, WasiHttp>(linker, T::http)?;
client::add_to_linker::<_, WasiHttp>(linker, T::http)?;
types::add_to_linker::<_, WasiHttp>(linker, T::http)?;
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/wasi-http/src/p3/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::p3::WasiHttpView;
use crate::p3::bindings::Proxy;
use crate::p3::bindings::Service;
use crate::p3::bindings::http::types::{ErrorCode, Request, Response};
use wasmtime::component::{Accessor, TaskExit};
use wasmtime::error::Context as _;

impl Proxy {
/// Call `wasi:http/handler#handle` on [Proxy] getting a [Response] back.
impl Service {
/// Call `wasi:http/handler#handle` on [Service] getting a [Response] back.
pub async fn handle(
&self,
store: &Accessor<impl WasiHttpView>,
Expand Down
Loading