Class: Apiphobic::Middleware::Validators::AcceptHeader

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/apiphobic/middleware/validators/accept_header.rb

Instance Method Summary collapse

Methods included from Configurable

#configuration, included

Constructor Details

#initialize(app) ⇒ AcceptHeader

Returns a new instance of AcceptHeader.



16
17
18
# File 'lib/apiphobic/middleware/validators/accept_header.rb', line 16

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/apiphobic/middleware/validators/accept_header.rb', line 20

def call(env)
  subdomain_request     = Requests::Subdomain.new(env)
  accept_header_request = Requests::AcceptHeader.new(env)
  accept_header         = Matchers::AcceptHeader.new(
                            application_name: configuration.application_name,
                          )
  subdomain             = Matchers::Subdomain.new(
                            allowed_subdomains: configuration.allowed_api_subdomains,
                          )

  if !subdomain.matches?(subdomain_request) ||
     accept_header.matches?(accept_header_request)

    @app.call(env)
  else
    Responses::InvalidAcceptHeader.call(env)
  end
end