Class: Rack::AuthorisedProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_authorised_proxy.rb

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AuthorisedProxy.



9
10
11
12
13
14
# File 'lib/rack_authorised_proxy.rb', line 9

def initialize(app, options = {})
  @app = app
  @expected_token = options.fetch(:expected_token, ENV.fetch('PROXY_TOKEN', nil))
  @header_name = options.fetch(:header_name, 'HTTP_X_PROXY_TOKEN').gsub('-', '_').upcase
  @not_allowed = options.fetch(:not_allowed, proc { |env| [403, {}, ['403 Forbidden']] })
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rack_authorised_proxy.rb', line 16

def call(env)
  unless @expected_token.nil? || ActiveSupport::SecurityUtils.secure_compare(@expected_token, env.fetch(@header_name, ''))
    return @not_allowed.call(env)
  end

  @app.call(env)
end