Skip to content
New issue

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

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

Already on GitHub? # to your account

add test/example for outbound request body streaming #1991

Merged
merged 4 commits into from
Oct 31, 2023

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Oct 30, 2023

No description provided.

@dicej dicej requested a review from rylev October 30, 2023 20:26
// won't necessarily have a chance to send the request body if they haven't started doing so yet (or, if they
// have started, they might not be able to finish before the connection is closed). See
// https://github.com/bytecodealliance/wasmtime/issues/7413 for details.
pub fn take_body_stream(&self) -> impl futures::Stream<Item = Result<Vec<u8>, streams::Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dicej is this a planned change to the 2.0 SDK?

(Also, would this explain why your sample works and #1985 drops?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and yes. The API change is necessary because there's no other way to work around bytecodealliance/wasmtime#7413, and I'm not sure when that will be fixed or whether it will be backported to Wasmtime 14 (and if it is, probably not in time for Spin 2.0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: here's a PR with the fix: bytecodealliance/wasmtime#7426

Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I think we'll want to revisit the streaming API in the future to see if we can make things less error prone, but given the current state of the world these changes look great.

examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs Outdated Show resolved Hide resolved
examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs Outdated Show resolved Hide resolved
examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs Outdated Show resolved Hide resolved
@@ -461,14 +461,24 @@ impl IncomingResponse {
/// # Panics
///
/// Panics if the body was already consumed.
pub fn into_body_stream(self) -> impl futures::Stream<Item = Result<Vec<u8>, streams::Error>> {
// TODO: This should ideally take ownership of `self` and be called `into_body_stream` (i.e. symmetric with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh... I think this whole API might need another look - it's hard to get the flow right. Oh well...

@dicej dicej enabled auto-merge (squash) October 31, 2023 17:11
@dicej dicej force-pushed the outbound-request-streaming-test branch from 0219a5d to bd7f08e Compare October 31, 2023 19:40
dicej added 4 commits October 31, 2023 13:50
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
This also removes some documentation from `spin_sdk::http::send` which turned
out to be incorrect; you _can_ safely await the returned future prior to
dropping the body handle.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Turns out there's no need to delay `await`ing the future returned from
`executor::outgoing_request_send`.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej dicej force-pushed the outbound-request-streaming-test branch from bd7f08e to 891493a Compare October 31, 2023 19:51
@vdice vdice disabled auto-merge October 31, 2023 19:52
@vdice vdice merged commit 00f7452 into fermyon:main Oct 31, 2023
5 of 7 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants