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:
parent
f29486ba3a
commit
4a75d9edfb
|
@ -14,6 +14,13 @@ module Sinatra
|
||||||
def accept
|
def accept
|
||||||
@env['HTTP_ACCEPT'].split(',').map { |a| a.strip }
|
@env['HTTP_ACCEPT'].split(',').map { |a| a.strip }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class Response < Rack::Response
|
class Response < Rack::Response
|
||||||
|
|
|
@ -6,4 +6,13 @@ describe 'Sinatra::Request' do
|
||||||
assert request.respond_to?(:user_agent)
|
assert request.respond_to?(:user_agent)
|
||||||
assert_equal 'Test', request.user_agent
|
assert_equal 'Test', request.user_agent
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue