Module: JSONAPI::Exceptions::HeadersExceptions

Defined in:
lib/easy/jsonapi/exceptions.rb,
lib/easy/jsonapi/exceptions/headers_exceptions.rb

Overview

Validates that Headers comply with the JSONAPI specification

Defined Under Namespace

Classes: InvalidHeader

Constant Summary collapse

JSONAPI_MEDIA_TYPES =

Media types that are complient with the spec if no parameters are included

['application/vnd.api+json', '*/*', 'application/*'].freeze

Class Method Summary collapse

Class Method Details

.check_compliance(env, config_manager = nil, opts = {}) ⇒ Object

Check jsonapi compliance



37
38
39
40
41
42
43
44
45
# File 'lib/easy/jsonapi/exceptions/headers_exceptions.rb', line 37

def self.check_compliance(env, config_manager = nil, opts = {})
  check_content_type(env)
  check_accept(env)

  hdrs = JSONAPI::Parser::HeadersParser.parse(env)
  usr_opts = { http_method: opts[:http_method], path: opts[:path] }
  err_msg = JSONAPI::Exceptions::UserDefinedExceptions.check_user_header_requirements(hdrs, config_manager, usr_opts)
  raise err_msg unless err_msg.nil?
end

.check_request(env, config_manager = nil, opts = {}) ⇒ Object

Check http verb vs included headers

Parameters:

  • env (Hash)

    The rack environment variable

  • config_manager (JSONAPI::ConfigManager) (defaults to: nil)

    The manager of user configurations

  • opts (Hash) (defaults to: {})

    Includes http_method, path, and contains_body values



30
31
32
33
# File 'lib/easy/jsonapi/exceptions/headers_exceptions.rb', line 30

def self.check_request(env, config_manager = nil, opts = {})
  check_compliance(env, config_manager, opts)
  check_http_method_against_headers(env, opts[:contains_body])
end