roc-lang / basic-webserver

A basic webserver in Roc
https://roc-lang.github.io/basic-webserver/
Universal Permissive License v1.0
72 stars 15 forks source link

add multipart/form-data parsing #62

Closed lukewilliamboswell closed 1 month ago

lukewilliamboswell commented 2 months ago

Adds support for multipart/form-data parsing as described in IETF RFC 7578 Returning Values from Forms: multipart/form-data

demo

This demo shows uploading a .csv, parse the multipart/form-data request body, saves the file to a temporary location and opens it.

demo-3

Anton-4 commented 2 months ago

Thanks @lukewilliamboswell :) Can you add a minimal example and expect script to test it?

lukewilliamboswell commented 2 months ago

Thanks @lukewilliamboswell :) Can you add a minimal example and expect script to test it?

No problem, can do.

lukewilliamboswell commented 1 month ago

@Anton-4 I've added an example that uses this.

I'm having trouble writing the expect script to drive this. Would you be able to help me with this?

demo

adfas

example image

roc-logo-small

example cURL

curl 'http://localhost:8000/' \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarykIHm2BDPibpfMOPG' \
  --data-raw $'------WebKitFormBoundarykIHm2BDPibpfMOPG\r\nContent-Disposition: form-data; name="fileToUpload"; filename="roc-logo-small.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundarykIHm2BDPibpfMOPG\r\nContent-Disposition: form-data; name="submit"\r\n\r\nUpload .png Image\r\n------WebKitFormBoundarykIHm2BDPibpfMOPG--\r\n'
Anton-4 commented 1 month ago

Would you be able to help me with this?

Sure :)

lukewilliamboswell commented 1 month ago

@Anton-4 I've removed Base64 from the platform. I realised we only need it in the example, so I just import it there.