diff --git a/crates/spin-test-virt/src/wasi/http.rs b/crates/spin-test-virt/src/wasi/http.rs index ae9744b..0692b75 100644 --- a/crates/spin-test-virt/src/wasi/http.rs +++ b/crates/spin-test-virt/src/wasi/http.rs @@ -164,7 +164,7 @@ pub struct OutgoingRequest { pub authority: RefCell>, pub path_with_query: RefCell>, pub headers: Fields, - body: Consumable, + pub body: Consumable, } impl exports::types::GuestOutgoingRequest for OutgoingRequest { @@ -259,6 +259,12 @@ impl OutgoingBody { } } +impl From for OutgoingBody { + fn from(i: IncomingBody) -> Self { + Self(i.0) + } +} + impl exports::types::GuestOutgoingBody for OutgoingBody { fn write(&self) -> Result { Ok(io::exports::streams::OutputStream::new( @@ -274,7 +280,7 @@ impl exports::types::GuestOutgoingBody for OutgoingBody { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct IncomingBody(io::Buffer); impl IncomingBody { diff --git a/crates/spin-test-virt/src/wasi/http_helper.rs b/crates/spin-test-virt/src/wasi/http_helper.rs index 5b5ee87..a2dbd30 100644 --- a/crates/spin-test-virt/src/wasi/http_helper.rs +++ b/crates/spin-test-virt/src/wasi/http_helper.rs @@ -34,7 +34,10 @@ impl exports::Guest for Component { authority, path_with_query, headers, - body: body.unwrap_or_else(IncomingBody::empty).into(), + // Either override the body with `incoming_body`, or use the body from the original request + body: body + .map(Into::into) + .unwrap_or_else(|| request.body.unconsume().map(Into::into)), }) }