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

No support for body as URLSearchParams #491

Open
azhiv opened this issue Dec 11, 2023 · 0 comments
Open

No support for body as URLSearchParams #491

azhiv opened this issue Dec 11, 2023 · 0 comments

Comments

@azhiv
Copy link

azhiv commented Dec 11, 2023

Description

The native fetch implemented in a browser (along with node-fetch) provide a complex behaviour when processing body. Namely, in case body is a URLSearchParams object, it adds this header 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' to the request and also serializes the corresponding form data.
The problem is that when intersecting the native fetch, Polly doesn't handle this case sending an empty body and a missing type header. Here's a link to the spec.

Shareable Source

const args = {
  username: 'username',
  password: 'password',
};

fetch('/api/v1/user/login', {
  method: 'POST',
  headers: {},
  body: new URLSearchParams(args),
})

The request above is incorrectly handled by Pollyjs, here's the har content for this request:

"postData": {
  "mimeType": "text/plain",
  "params": []
},

as opposed to what's there when I export Network activity into har in Chrome:

"postData": {
  "mimeType": "application/x-www-form-urlencoded;charset=UTF-8",
  "text": "username=username&password=password",
  "params": [
    {
      "name": "username",
      "value": "username"
    },
    {
      "name": "password",
      "value": "password"
    }
  ]
}

Should Pollyjs also handle this case?

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

No branches or pull requests

1 participant