Skip to content

Commit

Permalink
Correctly implement new-request.
Browse files Browse the repository at this point in the history
Previously, if the `incoming-body` override was `none` we set the body
to empty instead of defaulting to the existing body in `request`.

Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Jul 10, 2024
1 parent 74f0ee9 commit 58a516f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions crates/spin-test-virt/src/wasi/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub struct OutgoingRequest {
pub authority: RefCell<Option<String>>,
pub path_with_query: RefCell<Option<String>>,
pub headers: Fields,
body: Consumable<OutgoingBody>,
pub body: Consumable<OutgoingBody>,
}

impl exports::types::GuestOutgoingRequest for OutgoingRequest {
Expand Down Expand Up @@ -259,6 +259,12 @@ impl OutgoingBody {
}
}

impl From<IncomingBody> for OutgoingBody {
fn from(i: IncomingBody) -> Self {
Self(i.0)
}
}

impl exports::types::GuestOutgoingBody for OutgoingBody {
fn write(&self) -> Result<io::exports::streams::OutputStream, ()> {
Ok(io::exports::streams::OutputStream::new(
Expand All @@ -274,7 +280,7 @@ impl exports::types::GuestOutgoingBody for OutgoingBody {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct IncomingBody(io::Buffer);

impl IncomingBody {
Expand Down
5 changes: 4 additions & 1 deletion crates/spin-test-virt/src/wasi/http_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
})
}

Expand Down

0 comments on commit 58a516f

Please sign in to comment.