Class: Rage::OriginValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/middleware/origin_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, *allowed_origins) ⇒ OriginValidator

Returns a new instance of OriginValidator.



4
5
6
7
# File 'lib/rage/middleware/origin_validator.rb', line 4

def initialize(app, *allowed_origins)
  @app = app
  @validator = build_validator(allowed_origins)
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/rage/middleware/origin_validator.rb', line 9

def call(env)
  if @validator.call(env)
    @app.call(env)
  else
    Rage.logger.error("Request origin not allowed: #{env["HTTP_ORIGIN"]}")
    [404, {}, ["Not Found"]]
  end
end