Skip to content

Commit

Permalink
Merge pull request fermyon#107 from fermyon/replace-body
Browse files Browse the repository at this point in the history
Correctly implement new-request.
  • Loading branch information
rylev authored Jul 11, 2024
2 parents 8d44bd6 + 1d31834 commit 23ca498
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 23ca498

Please sign in to comment.