Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Move outgoing http body I/O into a store task #229

Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom
alexcrichton:prepare-for-accessor-ops
Jul 15, 2025
Merged

Move outgoing http body I/O into a store task #229
alexcrichton merged 2 commits intobytecodealliance:mainfrom
alexcrichton:prepare-for-accessor-ops

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit is in preparation for adding &Accessor parameters to
stream reads/writes. There are a number of fundamental cases that need
updating/refactoring throughout wasi-http and this is the first of a
small handful that are going to land ahead-of-time.

Specifically here the OutgoingRequestBody internally contained a
future which represented a StreamReader<u8> which was polled
externally on Hyper's own event loop (e.g. Tokio). This is no longer
going to be possible and streams are going to need to stay within the
store, so this commit does some refactoring.

The major changes here are:

  • The OutgoingRequestBody type is entirely removed.
  • A new BodyChannel type is added to have a mpsc::Receiver coming
    from the store into Hyper. This is a new channel added which
    represents the link going out of the store.
  • A new BodyWithContentLength combinator was added which handles the
    content-length-limiting side of the body.

Internally when sending an outgoing request the spawned task which takes
care of host I/O now also takes care of reading the stream in a loop and
forwarding the results along the channel arranged for the outgoing body.

Don't use a custom future, instead use an `async fn`.
This commit is in preparation for adding `&Accessor` parameters to
stream reads/writes. There are a number of fundamental cases that need
updating/refactoring throughout wasi-http and this is the first of a
small handful that are going to land ahead-of-time.

Specifically here the `OutgoingRequestBody` internally contained a
future which represented a `StreamReader<u8>` which was polled
externally on Hyper's own event loop (e.g. Tokio). This is no longer
going to be possible and streams are going to need to stay within the
store, so this commit does some refactoring.

The major changes here are:

* The `OutgoingRequestBody` type is entirely removed.
* A new `BodyChannel` type is added to have a `mpsc::Receiver` coming
  from the store into Hyper. This is a new channel added which
  represents the link going out of the store.
* A new `BodyWithContentLength` combinator was added which handles the
  content-length-limiting side of the body.

Internally when sending an outgoing request the spawned task which takes
care of host I/O now also takes care of reading the stream in a loop and
forwarding the results along the channel arranged for the outgoing body.
@alexcrichton
Copy link
Copy Markdown
Member Author

cc @rvolosatovs I'm going to go ahead and land this but happy to address any follow-up you run into.

@alexcrichton alexcrichton enabled auto-merge July 15, 2025 16:07
@alexcrichton alexcrichton added this pull request to the merge queue Jul 15, 2025
Merged via the queue into bytecodealliance:main with commit 73d715e Jul 15, 2025
43 checks passed
@alexcrichton alexcrichton deleted the prepare-for-accessor-ops branch July 15, 2025 16:48
alexcrichton added a commit to alexcrichton/wasip3-prototyping that referenced this pull request Jul 15, 2025
This is similar to bytecodealliance#229 in that it's preparation for adding `Accessor`
arguments to future/stream methods. This replaces
`Body::Guest::contents` with a `StreamReader<BytesMut>` instead of an
in-progress `'static` future. The major consequences of this are:

* `Response::into_http` now returns a lump "do this I/O in the store"
  object instead of separate values and/or generic futures.
* Guest-to-guest bodies no longer work if a `body` handle is dropped,
  notably a tombstone is left because reads cannot be cancelled at this
  time.
* Some test behavior changed because reads are not submitted immediately
  but are instead deferred to when the body is actually accessed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant