class Rack::AuthorisedProxy

Constants

VERSION

Public Class Methods

new(app, options = {}) click to toggle source
# 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

Public Instance Methods

call(env) click to toggle source
# 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