golemcloud / golemcloud/wasm-rquickjs

fetch: body specified in RequestInit should take precedence

Open Beginner friendly
#142 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
21
Forks
2
Avg merge
5d 2h
Merged PRs (30d)
21

Description

While trying to wrap a library using wasm-rquickjs, I noticed the following incorrect behavior:

fetch(
  new Request('https://api.example.com', {
    method: 'POST',
    body: "original"
  }),
  {  body: "overriden" }
)

It should send body as "overriden", however the fetch polyfill currently sends "original" to the endpoint instead.

As per https://developer.mozilla.org/en-US/docs/Web/API/RequestInit

You can also construct a Request with a RequestInit, and pass the Request to a fetch() call along with another RequestInit. If you do this, and the same option is set in both places, then the value passed directly into fetch() is used.

Currently the way how wasm-rquickjs generates the project really helped a bunch, I could manually patch the http.js file here to take options.body if specified and the wrapped library started working correctly!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/wasm-rquickjs/skeleton/src/builtin/http.js around line 73, where the fetch polyfill handles Request and RequestInit options. Reproduce the issue with the provided example and verify that the body passed directly to fetch takes precedence over the Request body.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.