diff --git a/lib/rack/method_override.rb b/lib/rack/method_override.rb index f56377711..06df21f7b 100644 --- a/lib/rack/method_override.rb +++ b/lib/rack/method_override.rb @@ -38,6 +38,9 @@ def allowed_methods def method_override_param(req) req.POST[METHOD_OVERRIDE_PARAM_KEY] rescue Utils::InvalidParameterError, Utils::ParameterTypeError + req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params" + rescue EOFError + req.get_header(RACK_ERRORS).puts "Bad request content body" end end end diff --git a/test/spec_method_override.rb b/test/spec_method_override.rb index 14ace0b17..bb72af9f3 100644 --- a/test/spec_method_override.rb +++ b/test/spec_method_override.rb @@ -66,14 +66,27 @@ def app "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x", "CONTENT_LENGTH" => input.size.to_s, :method => "POST", :input => input) - begin - app.call env - rescue EOFError - end + app.call env env["REQUEST_METHOD"].must_equal "POST" end + it "writes error to RACK_ERRORS when given invalid multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size.to_s, + Rack::RACK_ERRORS => StringIO.new, + :method => "POST", :input => input) + Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env + + env[Rack::RACK_ERRORS].rewind + env[Rack::RACK_ERRORS].read.must_match /Bad request content body/ + end + it "not modify REQUEST_METHOD for POST requests when the params are unparseable" do env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)") app.call env diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb index 469ae62ac..eff64116d 100644 --- a/test/spec_webrick.rb +++ b/test/spec_webrick.rb @@ -1,5 +1,6 @@ require 'minitest/autorun' require 'rack/mock' +require 'concurrent/utility/native_integer' require 'concurrent/atomic/count_down_latch' require File.expand_path('../testrequest', __FILE__)