rack/rack — pull request #749 by Wardrop (2014-10-24 01:46:35+00:00)
Title: Memoizing Request#POST

I've added logic to my application so when JSON data is POST'd to it, it's automatically parsed and merged with Request#POST. The processing is meant to transparent to the rest of the application. This is how I deal with JSON data posted to the server by JavaScript code on the client.

request.POST.merge!(JSON.parse('...'))

The problem is, if no form data has been POST'd, Request#POST returns a new empty hash every time it's called, so my `merge!` doesn't stick. Looking at the source code for Request#POST, it's easy to see the problem. I'm wondering if we can modify Request#POST so it memoizes the empty hash it returns if no form data exists, instead of returning a new hash every time.

Otherwise, I'm open to suggestions on how I could go about this another way that achieves the same result, but Request#POST returning a new hash every time seems wrong either way.