feat: allow returning an array of bytes from Rust workers #45
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.
Allow Rust workers to return an array of bytes instead of a String. Note that
wwsserializes the worker output as an UTF-8 JSON, so an arbitrary array of bytes may not be serializable. For this reason, we implemented this feature usingbase64to encode the output when the worker exports an array of bytes.Then,
wwswill look for thebase64flag in the serialized JSON. If it's true, it will perform the decoding process before sending the result back.The feature introduces a breaking change as we cannot now set the response body type as
String. I created a newContentenum that can represents both text and base64 responses.The change is pretty trivial:
Thanks to the implementation of the
Fromtrait, the way you pass the body to the response will continue as it's now:The statement
response.into()will initialize the rightContentenum type.The PR also updates the documentation and adds a new fun example called
pdf-create.It closes #44