tinyhttp / milliparsec

🌌 Tiniest body parser in the universe. Built for modern Node.js
https://npm.im/milliparsec
MIT License
165 stars 7 forks source link

Add form data support #5

Closed talentlessguy closed 1 month ago

talentlessguy commented 4 years ago

Forms are very commonly used, so it must be supported

previously we have parsec.form() but it was for urlencoded only, we need a separate function for forms with form data in it

related: #4

ilanru commented 1 year ago

Hey @talentlessguy I've stumbled on this issue and was wandering if it's still viable to have a go at it?

If so, can you suggest any pointers about the desired robustness of the solution? form data can be quite complex if I were to follow this: https://www.w3.org/TR/html401/interact/forms.html#h-17.13.3

talentlessguy commented 1 year ago

@ilanru easiest solution is just being able to parse text fields. if files are doable without introducing new dependencies, even better.

ilanru commented 1 year ago

Oh that was quick

Alright, I'll start with text fields and go from there, thanks

ilanru commented 1 year ago

Well, sorry about the long delay, life got in the way.

I've drafted a small pr with the suggested changes: https://github.com/tinyhttp/milliparsec/pull/21

It was not very complex to extract the file fields, but I am not sure what is the proper response structure and how should the files be encoded as at the moment they are converted to simple strings inside the p function.

Here's an example response for files from the implementation, any suggestions would be appreciated: "image": { "filename": "tumblr_2_250.gif", "value":"Content-Type: image/gif\r\n GIF89a������D2#$" }

einar-hjortdal commented 8 months ago

I would like formdata support too.

talentlessguy commented 8 months ago

@Coachonko you could continue the efforts of @ilanru if you'd like and I'll review the PR

talentlessguy commented 8 months ago

Well, sorry about the long delay, life got in the way.

I've drafted a small pr with the suggested changes: https://github.com/tinyhttp/milliparsec/pull/21

It was not very complex to extract the file fields, but I am not sure what is the proper response structure and how should the files be encoded as at the moment they are converted to simple strings inside the p function.

Here's an example response for files from the implementation, any suggestions would be appreciated: "image": { "filename": "tumblr_2_250.gif", "value":"Content-Type: image/gif\r\n GIF89a������D2#$" }

Just encode the value to Uint8Array

talentlessguy commented 1 month ago

form data is not supported, it wraps files into a File, which should take care of encoding