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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::Context as _;
use futures::join;
use test_programs::p3::wasi::http::handler;
use test_programs::p3::wasi::http::types::{ErrorCode, Headers, Method, Request, Scheme, Trailers};
Expand Down Expand Up @@ -47,13 +46,9 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
println!("writing enough");
{
let (request, mut contents_tx, trailers_tx, transmit) = make_request();
let (handle, (), ()) = join!(
async {
let res = handler::handle(request)
.await
.context("failed to send request")?;
anyhow::Ok(res)
},
let (handle, transmit, ()) = join!(
async { handler::handle(request).await },
async { transmit.await },
async {
let remaining = contents_tx.write_all(b"long enough".to_vec()).await;
assert!(
Expand All @@ -64,12 +59,9 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
trailers_tx.write(Ok(None)).await.unwrap();
drop(contents_tx);
},
async {
transmit.await.unwrap();
},
);
let res = handle.unwrap();
drop(res);
let _res = handle.expect("failed to send request");
transmit.expect("failed to transmit request");
}

println!("writing too little");
Expand All @@ -89,8 +81,11 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
trailers_tx.write(Ok(None)).await.unwrap();
},
);
let res = handle.unwrap();
drop(res);
let err = handle.expect_err("should have failed to send request");
assert!(
matches!(err, ErrorCode::HttpProtocolError),
"unexpected error: {err:#?}"
);
let err = transmit.expect_err("request transmission should have failed");
assert!(
matches!(err, ErrorCode::HttpRequestBodySize(Some(3))),
Expand All @@ -106,18 +101,15 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
async { transmit.await },
async {
let remaining = contents_tx.write_all(b"more than 11 bytes".to_vec()).await;
assert!(
remaining.is_empty(),
"{}",
String::from_utf8_lossy(&remaining)
);
assert_eq!(String::from_utf8_lossy(&remaining), "more than 11 bytes",);
drop(contents_tx);
_ = trailers_tx.write(Ok(None)).await;
},
);

let res = handle.unwrap();
drop(res);
// The the error returned by `handle` in this case is non-deterministic,
// so just assert that it fails
let _err = handle.expect_err("should have failed to send request");
let err = transmit.expect_err("request transmission should have failed");
assert!(
matches!(err, ErrorCode::HttpRequestBodySize(Some(18))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
request
.set_authority(Some("www.example.com"))
.expect("setting authority");
let (remaining, ()) =
futures::join!(contents_tx.write_all(b"request-body".to_vec()), async {
drop(request);
},);
assert!(!remaining.is_empty());
drop(request);
let remaining = contents_tx.write_all(b"request-body".to_vec()).await;
assert_eq!(String::from_utf8_lossy(&remaining), "request-body");
}
{
let headers = Headers::from_list(&[(
Expand Down
1 change: 0 additions & 1 deletion crates/wasi-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ pub mod types;
pub mod bindings;

#[cfg(feature = "p3")]
#[expect(missing_docs, reason = "work in progress")] // TODO: add docs
pub mod p3;

pub use crate::error::{
Expand Down
7 changes: 4 additions & 3 deletions crates/wasi-http/src/p3/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod generated {
world: "wasi:http/proxy",
imports: {
"wasi:http/handler/[async]handle": async | store | trappable | tracing,
"wasi:http/types/[drop]request": store | trappable | tracing,
"wasi:http/types/[drop]response": store | trappable | tracing,
"wasi:http/types/[method]request.consume-body": async | store | trappable | tracing,
"wasi:http/types/[method]response.consume-body": async | store | trappable | tracing,
"wasi:http/types/[static]request.new": async | store | trappable | tracing,
Expand All @@ -22,14 +24,13 @@ mod generated {
},
trappable_error_type: {
"wasi:http/types/error-code" => crate::p3::HttpError,
"wasi:http/types/header-error" => crate::p3::HeaderError,
"wasi:http/types/request-options-error" => crate::p3::RequestOptionsError,
},
});

mod with {
/// The concrete type behind a `wasi:http/types/fields` resource.
pub type Fields = crate::p3::MaybeMutable<http::HeaderMap>;

/// The concrete type behind a `wasi:http/types/request-options` resource.
pub type RequestOptions = crate::p3::MaybeMutable<crate::p3::RequestOptions>;
}
}
Expand Down
Loading