From 9775c25824feb35a5c42f3838d21c7e5faba9ca0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 13 Jan 2009 17:21:45 -0600 Subject: Update multipart tests to expose (another) bug in Rack's multipart parser --- actionpack/lib/action_controller/integration.rb | 11 ----------- .../lib/action_controller/middleware_stack.rb | 2 ++ actionpack/lib/action_controller/rack_ext.rb | 22 ++++++++++++++++++++++ .../lib/action_controller/rewindable_input.rb | 10 +++++++--- 4 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 actionpack/lib/action_controller/rack_ext.rb (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index 5b08e30d49..163ba84a3e 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -2,17 +2,6 @@ require 'stringio' require 'uri' require 'active_support/test_case' -# Monkey patch Rack::Lint to support rewind -module Rack - class Lint - class InputWrapper - def rewind - @input.rewind - end - end - end -end - module ActionController module Integration #:nodoc: # An integration Session instance represents a set of requests and responses diff --git a/actionpack/lib/action_controller/middleware_stack.rb b/actionpack/lib/action_controller/middleware_stack.rb index 2bccba2ba1..b94bf6ec4a 100644 --- a/actionpack/lib/action_controller/middleware_stack.rb +++ b/actionpack/lib/action_controller/middleware_stack.rb @@ -32,6 +32,8 @@ module ActionController else @klass.to_s.constantize end + rescue NameError + @klass end def active? diff --git a/actionpack/lib/action_controller/rack_ext.rb b/actionpack/lib/action_controller/rack_ext.rb new file mode 100644 index 0000000000..3b142307e9 --- /dev/null +++ b/actionpack/lib/action_controller/rack_ext.rb @@ -0,0 +1,22 @@ +module Rack + module Utils + module Multipart + class << self + def parse_multipart_with_rewind(env) + result = parse_multipart_without_rewind(env) + + 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 + + result + end + + alias_method_chain :parse_multipart, :rewind + end + end + end +end diff --git a/actionpack/lib/action_controller/rewindable_input.rb b/actionpack/lib/action_controller/rewindable_input.rb index 296d8aed22..058453ea68 100644 --- a/actionpack/lib/action_controller/rewindable_input.rb +++ b/actionpack/lib/action_controller/rewindable_input.rb @@ -15,15 +15,19 @@ module ActionController @io.rewind end + def string + @string + end + def method_missing(method, *args, &block) @io.send(method, *args, &block) end private def read_original_io - unless @str - @str = @io.read - @io = StringIO.new(@str) + unless @string + @string = @io.read + @io = StringIO.new(@string) end end end -- cgit v1.2.3 From b281a6a5b2137548501ef590379d7af5f6955d2d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 13 Jan 2009 17:26:29 -0600 Subject: Use Rack's MethodOverride lib [#1699 state:resolved] --- actionpack/lib/action_controller/middlewares.rb | 2 +- .../lib/action_controller/verb_piggybacking.rb | 24 ---------------------- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 actionpack/lib/action_controller/verb_piggybacking.rb (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb index 914750bc0c..0f038b8856 100644 --- a/actionpack/lib/action_controller/middlewares.rb +++ b/actionpack/lib/action_controller/middlewares.rb @@ -19,4 +19,4 @@ use "ActiveRecord::QueryCache", :if => lambda { defined?(ActiveRecord) } end use ActionController::RewindableInput -use ActionController::VerbPiggybacking +use Rack::MethodOverride diff --git a/actionpack/lib/action_controller/verb_piggybacking.rb b/actionpack/lib/action_controller/verb_piggybacking.rb deleted file mode 100644 index 86cde304a0..0000000000 --- a/actionpack/lib/action_controller/verb_piggybacking.rb +++ /dev/null @@ -1,24 +0,0 @@ -module ActionController - # TODO: Use Rack::MethodOverride when it is released - class VerbPiggybacking - HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) - - def initialize(app) - @app = app - end - - def call(env) - if env["REQUEST_METHOD"] == "POST" - req = Request.new(env) - if method = (req.parameters[:_method] || env["HTTP_X_HTTP_METHOD_OVERRIDE"]) - method = method.to_s.upcase - if HTTP_METHODS.include?(method) - env["REQUEST_METHOD"] = method - end - end - end - - @app.call(env) - end - end -end -- cgit v1.2.3