Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MethodOverride EOFError failure #1137

Merged
merged 3 commits into from Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/rack/method_override.rb
Expand Up @@ -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
21 changes: 17 additions & 4 deletions test/spec_method_override.rb
Expand Up @@ -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 = <<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
1 change: 1 addition & 0 deletions 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__)

Expand Down