mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.84k stars 213 forks source link

Normal error we see when busboy is called more than once #363

Closed aydincandan closed 1 month ago

aydincandan commented 1 month ago

quote from your comment https://github.com/mscdex/busboy/issues/353#issuecomment-1968069808
Here we need to think about what "consuming the entire request body" means, is it like "reading and deleting"? If so, why are we deleting it? OK, I know it seems ridiculous, but I don't want it to be deleted for my own busboy version. How should I change the busboy code that I will use so that my busboy code works again and again without giving an error (Unexpected end of form). Can you help me with this and guide me?

mscdex commented 1 month ago

"consumed the entire request body" means something has read all of the data from node's HTTP request stream. busboy can't parse anything if you don't give it anything to parse.

Whether you want to buffer the contents of an entire request stream in memory (not recommended for hopefully obvious reasons) or not is up to you. There is no deleting happening. There is no implicit copying happening. If another module reads and interprets all of the data from a stream and then afterwards you try to pass the same stream to another module, there won't be any data left for that module to read. That's just how a stream works.

There's nothing technically stopping you from feeding stream data into multiple modules in parallel, but in the issue you linked to the Express middleware functions that parse the request stream wait until the request stream is empty before passing execution to the next request handler function. That way the parsed form data will be available to those request handler functions.

aydincandan commented 1 month ago

Thank you very much for your kind and quick response.