Class: Rack::TlsTools::Hsts

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/tls_tools/hsts.rb

Overview

Constant Summary collapse

DEFAULT_MAX_AGE =

a year

3600 * 24 * 365

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Hsts

Returns a new instance of Hsts.



10
11
12
13
14
15
16
17
# File 'lib/rack/tls_tools/hsts.rb', line 10

def initialize(app, options = {})
  @app = app
  @options = {
    enable: true,
    max_age: DEFAULT_MAX_AGE,
    subdomains: false,
  }.merge(options)
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rack/tls_tools/hsts.rb', line 19

def call(env)
  @app.call(env).tap do |response|
    @request = Rack::Request.new env
    if @request.ssl? && @options[:enable]
      add_hsts_header! response[1]
    end
  end
end
OSZAR »