123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::SSL

Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/middleware/ssl.rb

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(app, options = {}) ⇒ SSL

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/ssl.rb', line 9

def initialize(app, options = {})
  @app = app

  @hsts = options.fetch(:hsts, {})
  @hsts = {} if @hsts == true
  @hsts = self.class.default_hsts_options.merge(@hsts) if @hsts

  @host    = options[:host]
  @port    = options[:port]
end

Class Method Details

.default_hsts_options

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/ssl.rb', line 5

def self.default_hsts_options
  { :expires => YEAR, :subdomains => false }
end

Instance Method Details

#call(env)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/ssl.rb', line 20

def call(env)
  request = Request.new(env)

  if request.ssl?
    status, headers, body = @app.call(env)
    headers.reverse_merge!(hsts_headers)
    flag_cookies_as_secure!(headers)
    [status, headers, body]
  else
    redirect_to_https(request)
  end
end