amberframework / amber

A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance.
https://amberframework.org
MIT License
2.58k stars 206 forks source link

Fixed the STD Lib monkey patch #1324

Open crimson-knight opened 1 year ago

crimson-knight commented 1 year ago

While trying to create a client to send POST requests with type multipart/form-data, my requests were being caught and messed up somehow.

This is infuriating to track down because the monkey patch was not at all obvious so I went ahead and removed this.

Overall the behavior is kind of weird. Changing form submissions from POST to other request types feels a bit dangerous.

There are a few tests that are failing for io reasons now. I'm running this branch in prod on my own project to see what kind of side effects it might have (yolo!)

Anyway, this was a huge blocker. Anyone using or trying to create an HTTP client of any kind would be affected.

crimson-knight commented 1 year ago

The monkey patch in the STD lib is to handle HTTP Tunneling from HTML forms that are using the regular form submission behavior but are being used for PATCH requests (ie the 'edit' view).

But because HTTP::Request from the STD lib is used for both incoming requests and outgoing requests, anyone who uses an HTTP::Client to try and send certain types of requests would encounter interference in how the requests are formed (which is how I found this).

Standard HTML forms only submit with GET and POST. So this means DELETE and PATCH requests will need some form of Javascript to be properly formed and sent.

I'm still working through a way to solve this. Obviously there are existing JS libraries out there and writing your own fetch is easy, which is how I'm working around the removal of this monkey patch for now.