Class: Rack::AuthorisedProxy
- Inherits:
-
Object
- Object
- Rack::AuthorisedProxy
- Defined in:
- lib/rack_authorised_proxy.rb
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ AuthorisedProxy
constructor
A new instance of AuthorisedProxy.
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, = {}) @app = app @expected_token = .fetch(:expected_token, ENV.fetch('PROXY_TOKEN', nil)) @header_name = .fetch(:header_name, 'HTTP_X_PROXY_TOKEN').gsub('-', '_').upcase @not_allowed = .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 |