Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created September 30, 2009 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baroquebobcat/198510 to your computer and use it in GitHub Desktop.
Save baroquebobcat/198510 to your computer and use it in GitHub Desktop.
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