Class: GyomuRuby::OrdinarySystemDevelopment::AllYourSiteAreBelongToSsl

Inherits:
Object
  • Object
show all
Defined in:
lib/gyomu_ruby/ordinary_system_development/all_your_site_are_belong_to_ssl.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AllYourSiteAreBelongToSsl

Returns a new instance of AllYourSiteAreBelongToSsl.



7
8
9
# File 'lib/gyomu_ruby/ordinary_system_development/all_your_site_are_belong_to_ssl.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/gyomu_ruby/ordinary_system_development/all_your_site_are_belong_to_ssl.rb', line 11

def call(env)
  if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
    @app.call(env)
  else
    url = Rack::Request.new(env).url.sub(/^http:/, 'https:')
    body = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
    [301, {'Location' => url, 'Content-Type' => 'text/html'}, [body]]
  end
end