wasm: fix standalone/multipart body conversion to JsValue #1364
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.
This is an attempt to fix the conflicting conversion code requried to turn a
Body
into aJsValue
depending if the body is standalone or if it is part of a form (aka multipart/form-data).The idea is to introduce a new variant to the
crate::wasm::body::Inner
enum that holds the actual content of a body. The new variant allowsBody.to_js_value
to have dedicated codepaths for standalone bodies and form parts. The new variant is contructed by the newBody.into_part
method. That method is called by thecrate::wasm::multipart::Part::new
constructor and turns an Inner::Body into the new Inner::MultipartPart variant.The drawback is that the new variant leads to some code duplication in the
Body
methods where it mostly shares code with theInner::Bytes
variant.For clarity the PR renames the
Inner::Multipart
variant toInner::MultipartForm
. It also adds new test cases to cover the serialization of different bodies either standalone or multipart.Thanks to @crapStone for pointing at the
Inner
enum in #1358 and @skystar-p for the original mutlipart conversion code in #1341.