node-fetch / node-fetch Public
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
feat(Body): Added support for BodyMixin.formData()
and constructing bodies with FormData
#1314
Conversation
body.formData()
body.formData()
body.formData()
and constructing bodies with FormData
Ready to be reviewed... |
Sorry for the dragged out review, I've been swamped lately...
Personally, there are a few things that I would like to clean up more, but I could send those in a follow up PR if you would prefer that? As I understood it this code was copied from another package, do you have a link to that package? (e.g. I think that the mark
/clear
functions are quite hard to follow, and could be done in a better way)
The only thing that has me a bit weary right now is the return
statements inside the for loop. I really think that this parsing will return garbage data back if the response is malformed. Personally, I think it's better to throw in those cases, so that no one starts relying on improper parsing which we might break in a future update. That being said, since you did say that you wanted to leave it as is I won't push it further
Would you be open to me addressing that in a follow up PR, after testing what the browser does, or do you want that behaviour?
Apart from that, great PR! Nice to get this in
Also, I'm also maintaining Multer which parses multipart data, and I've been interested in switching out the parser to a bit more modern/simpler one. What do you think about keeping this code in a separate package that both node-fetch and multer could depend on?
I think that'd be great, as long as it doesn't conflict with the standard compatibility of fetch |
The code is from an older version of formidable that i ported to https://github.com/github/fetch a while back (to be more browser friendlier (without the need of having Here is theirs new and updated code: https://github.com/node-formidable/formidable/blob/master/src/parsers/Multipart.js Formidable have been tested with a variety of different multipart uploads and it seems pretty speedy at parsing the payload. This is the official spec: https://andreubotella.com/multipart-form-data
Sure, As long as the body can be splittet up in chunks (anywhere) and parse different amount of bytes (even if it's splited in the middle of a boundary) and be streamable, then i'm fine with it. It would also be nice if we could write very large files to the disk instead of keeping it in the memory also. and then use our blobs
I think this would be a grate fit for the stream-consumers it's mostly a straight out copy from undici BodyMixin that made it into node.js core. it already uses fetch-blob and is also written in ESM + that it's new so not so many breaking changes for some ppl It dose not have formData doe since FormData isn't implemented in NodeJs but it could be one day? there is issues about bringing in FormData into node Personally i would like to remove the |
I think that we are already working in a different way in the specific return statements that I talked about, because their Porting over the tests would be great, also adding some test case that we run both against our parser and the browser equivalent...
For Multer I would probably need something a bit more low level, since we are doing field and size validation on the fly, and also stream the files to temporary files on disk Depends on how the API would look of course!
|
I was kind of thinking to make a low-level multipart parser as part of my |
fyi, I already went ahead and removed it... (put a warning sign on it) |
# Conflicts: # package.json # src/utils/form-data.js
@jimmywarting seems to be a conflict in @Richienb would you be able to review this? |
Oh this is exciting. Can't wait to see this merged. |
Purpose
response.formData()
andrequest.formData()
new Request(url, {body: formData})
but alsonew Response(formData)
as it's supposed to be (only supported Request before...)URLSearchParam
to a formData as it dose in browser/specThis would be a great addition so you can avoid having to depend on some external multiparty, formidable, busboy or any other body parser packages. that all have some different (non-speced) apis that you would need to learn.
Instead you could just do:
Changes
Additional information
Maybe thinking it would be nice to expose FormData, Blob and File from index.js so they are accessible, thoughts?
Think we have had this discussion before with exposing Blob before... #392
closes #199
closes #1118
closes #1293
closes #876