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

Conversation

@rvolosatovs
Copy link
Contributor

@rvolosatovs rvolosatovs commented Sep 9, 2025

This PR addresses two gaps in current wasi:http:

  • {request,response}::new return a future<result<_, error-code>>, but in case that consume-body is called on a request/response originating from this constructor, there is no way for the component to actually communicate a result on that future.
  • consume-body is a method on request/response, but it can only be called once. That introduces complexity for the implementers and a potential hazard for the users, for example:
export wasi:http/handler#handle(req)
   res = wasi:http/handler#handle(req)
   res.consume_body()
   return res

Whether returning a response, body of which has been consumed, is valid or not is not obvious.

To address these issues:

  • Take future<result<_, error-code>> as parameter in consume-body (see [v0.3]: Changes to consume-body #176 for more details)
  • Make consume-body a static function moving the request/response it's called on.

A note on partial body read use case:
Some implementations may want to read some data from the body, but pass along the rest.
Such use cases are enabled with a pattern as follows:

export wasi:http/handler#handle(req)
   (tx, rx) = future()
   (body, trailers) = wasi:http/types.request#consume_body(req, rx)
   stream.read(body, 8) // read 8 bytes from body stream
   headers = wasi:http/types.fields()
   (res, result) = wasi:http/types.response#new(headers, Some(body), trailers, None)
   spawn(async {
      tx.send(result.await)
   })
   return res

Closes #176
Wasmtime implementation: bytecodealliance/wasmtime#11653

@rvolosatovs rvolosatovs force-pushed the p3/consume-body branch 2 times, most recently from e6b902c to a26dd9c Compare September 9, 2025 08:22
@rvolosatovs rvolosatovs marked this pull request as ready for review September 9, 2025 10:21
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@lukewagner lukewagner merged commit e3df7c1 into WebAssembly:main Sep 15, 2025
1 check passed
@rvolosatovs rvolosatovs deleted the p3/consume-body branch September 15, 2025 16:11
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.

[v0.3]: Changes to consume-body

3 participants