Skip to content
Browse files

Use Request#ssl? for Request#secure? if available. Improve Request#se…

…cure? implementation (adjust to Request#ssl? in rack master).
  • Loading branch information...
1 parent 95a5bab commit cf188507ca52fb172fffe40b92f77c4bf10968b4 @rkh rkh committed
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/sinatra/base.rb
View
14 lib/sinatra/base.rb
@@ -17,10 +17,16 @@ def accept
@env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.split(';')[0].strip }
end
- # Whether or not the web server (or a reverse proxy in front of it) is
- # using SSL to communicate with the client.
- def secure?
- (@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme']) == 'https'
+ if Rack.release <= "1.2"
+ # Whether or not the web server (or a reverse proxy in front of it) is
+ # using SSL to communicate with the client.
+ def secure?
+ @env['HTTPS'] == 'on' or
+ @env['HTTP_X_FORWARDED_PROTO'] == 'https' or
+ @env['rack.url_scheme'] == 'https'
+ end
+ else
+ alias secure? ssl?
end
end

0 comments on commit cf18850

Please sign in to comment.
Something went wrong with that request. Please try again.