Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 4a75d9edfb83b7c46ec7626cbff22f0cef7e2fc6 1 parent f29486b
@rtomayko rtomayko authored
Showing with 16 additions and 0 deletions.
  1. +7 −0 lib/sinatra/base.rb
  2. +9 −0 test/request_test.rb
View
7 lib/sinatra/base.rb
@@ -14,6 +14,13 @@ def user_agent
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
9 test/request_test.rb
@@ -6,4 +6,13 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.