Created
May 26, 2010 17:48
Revisions
-
mrship created this gist
May 26, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ module Rack class EnsureSsl def initialize(app) @app = app end def call(env) ssl_request?(env) ? @app.call(env) : ssl_redirect(env) end private def ssl_request?(env) env["HTTP_X_FORWARDED_PROTO"] == "https" end def ssl_location(env) "https://" + env['HTTP_HOST'] + env['PATH_INFO'] end def ssl_redirect(env) [ 301, { 'Content-Type' => 'text/html', 'Location' => ssl_location(env) }, %{ <html> <head> <title>SSL Redirect</title> </head> <body> <p>The requested path must be requested via SSL. You are now being redirected.</p> </body> </html> } ] end end end