1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

don't override Request#params/#user_agent when rack >= 1.1

This commit is contained in:
Ryan Tomayko 2010-01-28 05:24:40 -08:00
parent 466cc74b8f
commit e7b5985f99

View file

@ -18,24 +18,28 @@ module Sinatra
# The request object. See Rack::Request for more info:
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
class Request < Rack::Request
def user_agent
@env['HTTP_USER_AGENT']
end
# Returns an array of acceptable media types for the response
def accept
@env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.strip }
end
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
def secure?
(@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme']) == 'https'
end
# Override Rack < 1.1's Request#params implementation (see lh #72 for
# more info) and add a Request#user_agent method.
# XXX remove when we require rack > 1.1
if Rack.release < '1.1'
def params
self.GET.update(self.POST)
rescue EOFError, Errno::ESPIPE
self.GET
end
def secure?
(@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme']) == 'https'
def user_agent
@env['HTTP_USER_AGENT']
end
end
end