class Apiphobic::Middleware::Validators::AcceptHeader

Public Class Methods

new(app) click to toggle source
# File lib/apiphobic/middleware/validators/accept_header.rb, line 16
def initialize(app)
  @app = app
end

Public Instance Methods

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