title: How exactly do you use Rack's env hash?
body: <p>I have a Rails 4.2 app with a heavy file upload traffic.</p>
  
  <p>I want to override <code>rack.multipart.tempfile_factory</code> in order to provide additional behaviour associated with the temporary files Rack creates under the hood when accepting file uploads.</p>
  
  <p>So where and how do I change Rack's <code>env</code> hash <strong>exactly</strong>? Tried doing <code>env['...'] = ...</code> inside an initializer, said <code>env</code> is undefined. Changing it to <code>ENV</code> raises an error saying it cannot convert a lambda to String (<code>rack.multipart.tempfile_factory</code> requires a lambda so I can't just change it to a String). Using <code>request.env</code> inside a controller method has no effect whatsoever. I tested the last by copy-pasting the stock Rack factory's one line of code and added writing a random number to a file with a fixed path; that file never got created in the first place after uploading a few files, so there you go.</p>
  
  <p>I am looking for an official solution and don't have the intention to monkey-patch Rack. Its spec states this is possible, so how exactly should I be doing it?</p>
  
  <p>Of course, if all else fails, I will resort to hacking, but I'd prefer to hear the official ways of doing it first.</p>
  
  <p><em>(And while we're at this, can you also recommend a gemless solution to override <code>rack.hijack_io</code>, with some real-world examples? Searching for that thing in particular wasn't very helpful, nobody seems to provide an end-to-end working solution, only bits &amp; pieces).</em></p>
  
  <p>Thank you for your consideration.</p>