Skip to content

Commit

Permalink
Write MethodOverride errors to RACK_ERRORS
Browse files Browse the repository at this point in the history
  • Loading branch information
carlzulauf committed Dec 29, 2016
1 parent db45a93 commit ea8479d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rack/method_override.rb
Expand Up @@ -37,7 +37,10 @@ def allowed_methods

def method_override_param(req)
req.POST[METHOD_OVERRIDE_PARAM_KEY]
rescue Utils::InvalidParameterError, Utils::ParameterTypeError, EOFError
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
16 changes: 16 additions & 0 deletions test/spec_method_override.rb
Expand Up @@ -71,6 +71,22 @@ def app
env["REQUEST_METHOD"].must_equal "POST"
end

it "writes error to RACK_ERRORS when given invalid multipart form data" do
input = <<EOF
--AaB03x\r
content-disposition: form-data; name="huge"; filename="huge"\r
EOF
env = Rack::MockRequest.env_for("/",
"CONTENT_TYPE" => "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
Expand Down

0 comments on commit ea8479d

Please sign in to comment.