Created
September 30, 2009 22:24
-
-
Save baroquebobcat/198510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RequireSSL | |
def initialize app,options={} | |
@app = app | |
end | |
def call_ env | |
request = ::Rack::Request.new env | |
unless secure? env | |
[302,{"Location"=> request.url.sub('http://','https://')},''] | |
else | |
@app.call env | |
end | |
end | |
def call env | |
self.dup.call_ env | |
end | |
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 271 + modifications | |
def secure? env | |
env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment