question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect content-type parsing in actions

See original GitHub issue

Describe the bug

When using a simple fetch to an endpoint like so: fetch(‘/login’, {method: “POST”, body: new URLSearchParams(‘key’, ‘value’)})

This is sent by Chrome and Safari as a POST request with the following content-type header: Content-Type: application/x-www-form-urlencoded;charset=UTF-8

But https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/server/page/actions.js checks the content-type value by splitting on "; " (note the space).

Therefore I cannot use the above fetch call because the endpoint returns: Actions expect form-encoded data (received application/x-www-form-urlencoded;charset=UTF-8)

I think this is a bug and that you should instead split on “;” (without space).

Reproduction

Use a simple fetch to an endpoint (/login/+page.server.js) like so: fetch(‘/login’, {method: “POST”, body: new URLSearchParams(‘key’, ‘value’)})

Logs

No response

System Info

any system

Severity

serious, but I can work around it

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tcc-sejohnsoncommented, Oct 8, 2022

I’ll fix this. The easy solution would be to split on ; and trim the results. Any objections?

0reactions
SylvainGarriguescommented, Oct 10, 2022

Thanks for such a quick fix, great job.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve parse error when HTTP content-type header is ...
Problem. DataPower throws parse error with the following message: implied action Parse input as SOAP, attempt pipeline failed: illegal ...
Read more >
Incorrect encoding of contentType in AJAX Call for MVC Action
I am trying to call an AJAX function to transfer some JSON data (Roughly 38Kb in size) which will be cast onto a...
Read more >
Content-Type - HTTP - MDN Web Docs - Mozilla
In responses, a Content-Type header provides the client with the actual content type of the returned content. This header's value may be ignored ......
Read more >
Accepting Raw Request Body Content in ASP.NET Core API ...
<summary> /// Formatter that allows content of type text/plain and application/octet stream /// or no content type to be parsed to raw data....
Read more >
Solved: application/x-www-form-urlencoded content type err...
The problem with the webhook is that it sends the payload with a content type ... What I first do is select the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found