This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Change the API to allow streaming & no callback to alloc #43
Merged
Conversation
This file contains 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
This makes a couple changes to the API to make it closer to other WASI APIs. `req()` returns a handle to a `Response` object, along with the status code. A `Response` object can be then used to: - Read individual headers - Read the body in a streaming fashion. A `body_read()` function pulls as many bytes as the client wants, and returns `0` when the end of the stream is reached. This makes it compatible with streaming, doesn't require any dynamic memory allocation, and allows the client to control the maximum response size it's willing to accept. For conveniency, the Rust and AssemblyScript bindings also have a `readAll` function that reads everything until the end and puts that into a dynamically allocated array. Usage in an app using wasmtime is now similar to wasi (core) and other WASI proposals, with an object and an `add_to_linker()` function. Errors are a little bit easier to keep track of, by using Rust errors, that are converted to return codes when needed. WITX is supposed to provide eventually provide the magic to get error strings from that. Dependencies have been updated, especially `wasmtime`.
radu-matei
reviewed
Mar 29, 2021
radu-matei
reviewed
Mar 29, 2021
This is great, @jedisct1! |
Could you please add some comments to the exported items? |
Of course! Done! |
radu-matei
approved these changes
Mar 30, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
I do have a few follow-up PRs that I will open, but at first they will be mostly cosmetic.
Thank you so much for this, @jedisct1!
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.
Hi!
This is a proposal to support streaming (at least in the API and for responses), avoid the
alloc
function, and simplify the current implementation while making it closer to other WASI proposals.req()
now returns a handle to aResponse
object, along with the status code.A
Response
object can be then used to:A
body_read()
function pulls as many bytes as the client wants, and returns0
when the end of the stream is reached.This makes it compatible with streaming, doesn't require any dynamic memory allocation, and allows the client to control the maximum response size it's willing to accept.
For conveniency, the Rust and AssemblyScript bindings also have a
readAll
function that reads everything until the end and puts that into a dynamically allocated array.Usage in an app using wasmtime is now similar to wasi (core) and other WASI proposals, with an object and an
add_to_linker()
function.Errors are a little bit easier to keep track of, by using Rust errors, that are converted to return codes when needed. WITX is supposed to provide eventually provide the magic to get error strings from that.
Dependencies have been updated, especially
wasmtime
.