Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly implement new-request. #107

Merged
merged 1 commit into from
Jul 11, 2024
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
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