Sha256: e0e32ca935b3b5166e52587c0cab383cfee2b835a14fc8c107493b3258409528

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

require 'easy/jsonapi/collection'
require 'easy/jsonapi/header_collection'

require 'easy/jsonapi/item'
require 'easy/jsonapi/header_collection/header'

require 'easy/jsonapi/exceptions/headers_exceptions'

module JSONAPI
  module Parser

    # Header parsing logic
    module HeadersParser
      
      # @param env [Hash] The rack envirornment hash
      # @return [JSONAPI::HeaderCollection] The collection of parsed header objects
      def self.parse(env)
        h_collection = JSONAPI::HeaderCollection.new
        env.each_key do |k|
          if k.start_with?('HTTP_') && (k != 'HTTP_VERSION')
            h_collection << JSONAPI::HeaderCollection::Header.new(k[5..], env[k])
          elsif k == 'CONTENT_TYPE'
            h_collection << JSONAPI::HeaderCollection::Header.new(k, env[k])
          end
        end
        h_collection
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
easy-jsonapi-1.0.0 lib/easy/jsonapi/parser/headers_parser.rb