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

undici parses FormData bodies incorrectly #2890

Closed
KhafraDev opened this issue Feb 29, 2024 · 4 comments · Fixed by #2911
Closed

undici parses FormData bodies incorrectly #2890

KhafraDev opened this issue Feb 29, 2024 · 4 comments · Fixed by #2911
Labels
bug Something isn't working

Comments

@KhafraDev
Copy link
Member

KhafraDev commented Feb 29, 2024

The parsing should be synchronous. The spec makes it abundantly clear that you buffer the body in memory and then parse it, which we do for every other body mixin. It also doesn't make much sense for us to parse the body asynchronously only for us to buffer it into memory later on. It's not meant for server environments and we shouldn't give people a false sense of security.

  • It's also extremely slow
  • We also fail a large amount of WPTs regarding formdata parsing because of this.
  • There are a large number of hacks/workarounds for shortcomings of our current approach.
  • Every other platform (Deno, Webkit/bun, Chrome, and Firefox) parse it synchronously. I've previously posted proof of this in an issue but it'd be hard to track it down.

If someone wants to stream the formdata parsing:

const response = await fetch('https://formdata.idk.com')
const busboy = new Busboy({ headers: { 'content-type': response.headers.get('content-type') } })

Readable.from(response.body).pipe(busboy)
@KhafraDev KhafraDev added the bug Something isn't working label Feb 29, 2024
@KhafraDev
Copy link
Member Author

@climba03003
Copy link
Contributor

I am supporting it follows by spec.

Only concern is that if it buffered the whole content to memory, what will happen if it exhausted the memory?
An error, or crash? I hope it should be the former.

Can undici provide a handy tools for async consume?

@KhafraDev
Copy link
Member Author

KhafraDev commented Mar 1, 2024

The same thing that happens currently, it'll crash. The body is parsed asynchronously but then buffered in memory right now.

I don't think undici needs to provide a way of efficiently parsing multipart/form-data bodies, busboy and alternatives do that already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants