I ran into an unusual problem (rails 3.1.3, rack 1.3.6) while using rack-multipart_related (https://github.com/lucasfais/rack-multipart_related) as middleware to handle parsing of a multipart containing an image. While parsing the POST request, there's the following code in rack/request.rb:
def POST
if @env["rack.input"].nil?
raise "Missing rack.input"
elsif @env["rack.request.form_input"].eql? @env["rack.input"]
@env["rack.request.form_hash"]
elsif form_data? || parseable_data?
I noticed that if the size of the image was small, a StringIO is created containing the request data and as expected,
@env["rack.request.form_input"].eql? @env["rack.input"]
returns true. Both operands point to the same StringIO, the object_id's are the same.
If the image being uploaded was larger, a Tempfile seems to be created for the input and I get a weird result in this same piece of code:
(rdb:1) p @env["rack.request.form_input"]
#<File:/var/folders/_c/0c66qtcm8xjcns006s6bhgzr0000gn/T/thin-body20120604-68121-12dpbf1>
(rdb:1) p @env["rack.request.form_input"].class
Tempfile
(rdb:1) p @env["rack.request.form_input"].object_id
70289039522540
(rdb:1) p @env["rack.input"]
#<File:/var/folders/_c/0c66qtcm8xjcns006s6bhgzr0000gn/T/thin-body20120604-68121-12dpbf1>
(rdb:1) p @env["rack.input"].object_id
70289039522540
(rdb:1) p @env["rack.request.form_input"] == @env["rack.input"]
true
(rdb:1) p @env["rack.request.form_input"].eql?(@env["rack.input"])
false
So, == returns that the operands, which are the same Tempfile, are equivlent, but .eql? returns false.
I have a couple questions...
1) Anyone have any idea what might cause this?
2) What controls whether a StringIO or Tempfile is created when parsing a request object?
Thanks!
dave