Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception to sending formdata in webworker #4969

Closed
wants to merge 2 commits into from
Closed

fix: exception to sending formdata in webworker #4969

wants to merge 2 commits into from

Conversation

0x30
Copy link
Contributor

@0x30 0x30 commented Sep 20, 2022

The following code is a request to send fromdata through axios and xhr at the same time

// create formdata
const file = new File(
  [Uint8Array.from(atob(btoa("abc")), (c) => c.charCodeAt(0)).buffer],
  "a.png",
  { type: "image/png" }
);

const form = new FormData();
form.append("file", file);

// axios send
axios.request({ method: "post", url: "/api_axios", data: form });

// xhr send
const xhr = new XMLHttpRequest();
xhr.open("POST", "api_xhr");
xhr.send(form);

Put the above methods into browser to run and web worker to run respectively

browser axios Request Header abstract

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary6OBbVuvmtQJTBd6D

browser xhr Request Header abstract

Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryLY8kGoWmnvspdjMs

The above is no problem, of course, when you put the code into web worker to run, it will appear

web worker axios Request Header abstract

Content-Type: application/x-www-form-urlencoded

web worker xhr Request Header abstract

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary6trgIn70ilzcBsuh

At this time, the performance of xhr is normal, but axios has an exception.

To solve this problem I made the following changes. As for why not directly modify the isStandardBrowserEnv method, but create a new isStandardBrowserWebWorkerEnv method, the main reason is that many methods that rely on isStandardBrowserEnv use document in the follow-up.

@0x30 0x30 closed this by deleting the head repository Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants