This repository was archived by the owner on Nov 25, 2025. It is now read-only.
fix(p3): remove body accessors#161
Closed
rvolosatovs wants to merge 1 commit intoWebAssembly:mainfrom
Closed
Conversation
Currently, there are two ways to acquire a handle to the incoming request/response body handle: 1. Call `body` method on the request/response 2. Call `into-parts` static function on the request/response Assume pseudocode: ``` body := response.body() stream := body.stream() stream.read(buf) drop(stream) drop(body) // Forgetting this would cause a trap (_, body) := Response::into_parts(response) ``` There are quite a few issues in the example above. 1. It's very easy to make a mistake and cause a runtime trap, developers must very closely follow the WIT definition and read documentation to avoid a crash at runtime. 2. The host must do a lot of work and state tracking to e.g. ensure underlying body stream state synchronisation. If `body` method can be called at most once, that simplifes the task and potentially, the host could *move* the ownership of the body into the returned resource and *move* it back on `drop` of the body resource. Regardless of the approach and semantics, introducing multiple accessors for the `body` requires increased complexity in the host. To fix this, simply remove the `body` accessors. This way only a single way to acquire a body resource exists, which eliminates the possibility of misusing the interface by the application developer and simplifies implementation in the host. Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Member
|
Depending on the resolution to #156, that might justify the continued existence of the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, there are two ways to acquire a handle to the incoming request/response body handle:
bodymethod on the request/responseinto-partsstatic function on the request/responseAssume pseudocode:
There a few issues in the example above.
bodymethod can be called at most once, that simplifes the task and potentially, the host could move the ownership of the body into the returned resource and move it back ondropof the body resource. Regardless of the approach and semantics, introducing multiple accessors for thebodyrequires increased complexity in the host.To fix this, simply remove the
bodyaccessors. This way only a single way to acquire a body resource exists, which eliminates the possibility of misusing the interface by the application developer and simplifies implementation in the host.This is an alternative solution to #159, will mark that PR as draft.
Closes #159