Skip to content

Commit

Permalink
Don't try to rewind CGI input
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Dec 29, 2008
1 parent 48bbf3f commit 5db554e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def POST
Utils::Multipart.parse_multipart(env)
@env["rack.request.form_vars"] = @env["rack.input"].read
@env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"])
@env["rack.input"].rewind
@env["rack.input"].rewind if @env["rack.input"].respond_to?(:rewind)
end
@env["rack.request.form_hash"]
else
Expand Down
16 changes: 13 additions & 3 deletions test/spec_rack_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@
input.read.should.equal "foo=bar&quux=bla"
end

specify "does not rewind unwindable CGI input" do
input = StringIO.new("foo=bar&quux=bla")
input.instance_eval "undef :rewind"
req = Rack::Request.new \
Rack::MockRequest.env_for("/",
"CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar',
:input => input)
req.params.should.equal "foo" => "bar", "quux" => "bla"
end

specify "can get value by key from params with #[]" do
req = Rack::Request.new \
Rack::MockRequest.env_for("?foo=quux")
Expand Down Expand Up @@ -437,13 +447,13 @@
specify "memoizes itself to reduce the cost of repetitive initialization" do
env = Rack::MockRequest.env_for("http://example.com:8080/")
env['rack.request'].should.be.nil

req1 = Rack::Request.new(env)
env['rack.request'].should.not.be.nil
req1.should.equal env['rack.request']

rack_request_object_id = env['rack.request'].object_id

req2 = Rack::Request.new(env)
env['rack.request'].should.not.be.nil
rack_request_object_id.should.be.equal env['rack.request'].object_id
Expand Down

0 comments on commit 5db554e

Please sign in to comment.