Fix Request#params on PUT requests [#72]

Works around an issue introduced in Rack 0.9.0 with
request body params not being parsed when the request method
is PUT. This should be reverted once a fix lands in Rack.

Ticket for Rack fix:
http://rack.lighthouseapp.com/projects/22435-rack/tickets/20

More:
http://sinatra.lighthouseapp.com/projects/9779/tickets/72
This commit is contained in:
Ryan Tomayko 2009-01-15 06:45:38 -08:00
parent f29486ba3a
commit 4a75d9edfb
2 changed files with 16 additions and 0 deletions

View File

@ -14,6 +14,13 @@ module Sinatra
def accept
@env['HTTP_ACCEPT'].split(',').map { |a| a.strip }
end
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
def params
self.GET.update(self.POST)
rescue EOFError => boom
self.GET
end
end
class Response < Rack::Response

View File

@ -6,4 +6,13 @@ describe 'Sinatra::Request' do
assert request.respond_to?(:user_agent)
assert_equal 'Test', request.user_agent
end
it 'parses POST params when Content-Type is form-dataish' do
request = Sinatra::Request.new(
'REQUEST_METHOD' => 'PUT',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'rack.input' => StringIO.new('foo=bar')
)
assert_equal 'bar', request.params['foo']
end
end