Skip to content

Commit

Permalink
Remove code for handling the possibility that rack.input may not be r…
Browse files Browse the repository at this point in the history
…ewindable, because rack.input is now required to be rewindable.
  • Loading branch information
FooBarWidget committed Apr 14, 2009
1 parent 8ff87d4 commit 95f068e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
7 changes: 1 addition & 6 deletions lib/rack/request.rb
Expand Up @@ -145,12 +145,7 @@ def POST
@env["rack.request.form_vars"] = form_vars
@env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars)

begin
@env["rack.input"].rewind if @env["rack.input"].respond_to?(:rewind)
rescue Errno::ESPIPE
# Handles exceptions raised by input streams that cannot be rewound
# such as when using plain CGI under Apache
end
@env["rack.input"].rewind
end
@env["rack.request.form_hash"]
else
Expand Down
8 changes: 2 additions & 6 deletions lib/rack/utils.rb
Expand Up @@ -302,6 +302,7 @@ def self.parse_multipart(env)
buf = ""
content_length = env['CONTENT_LENGTH'].to_i
input = env['rack.input']
input.rewind

boundary_size = boundary.size + EOL.size
bufsize = 16384
Expand Down Expand Up @@ -384,12 +385,7 @@ def self.parse_multipart(env)
break if buf.empty? || content_length == -1
}

begin
input.rewind if input.respond_to?(:rewind)
rescue Errno::ESPIPE
# Handles exceptions raised by input streams that cannot be rewound
# such as when using plain CGI under Apache
end
input.rewind

params
end
Expand Down
10 changes: 0 additions & 10 deletions test/spec_rack_request.rb
Expand Up @@ -93,16 +93,6 @@
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 "cleans up Safari's ajax POST body" do
req = Rack::Request.new \
Rack::MockRequest.env_for("/", :input => "foo=bar&quux=bla\0")
Expand Down
22 changes: 0 additions & 22 deletions test/spec_rack_utils.rb
Expand Up @@ -326,28 +326,6 @@ def context env, app=@app; app.call(env); end
input.read.length.should.equal 197
end

specify "does not try to rewind input if it is not supported" do
options = multipart_fixture(:text)
input = options[:input]
input.instance_eval "undef :rewind"
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
params["files"][:filename].should.equal "file1.txt"
end

specify "does not try to rewind input Apache/CGI input" do
options = multipart_fixture(:text)
input = options[:input]
input.instance_eval do
def rewind; raise Errno::ESPIPE; end
end
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
params["files"][:filename].should.equal "file1.txt"
end

private
def multipart_fixture(name)
file = File.join(File.dirname(__FILE__), "multipart", name.to_s)
Expand Down

1 comment on commit 95f068e

@edmz
Copy link

@edmz edmz commented on 95f068e Apr 29, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the rescue code breaks rack on the latest Ruby Enterprise Edition. I don't really know the cause, I just wanted to let you know.

Please sign in to comment.