Class: Castle::Headers::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/castle/headers/filter.rb

Overview

used for preparing valuable headers list

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • request (Rack::Request)


20
21
22
23
# File 'lib/castle/headers/filter.rb', line 20

def initialize(request)
  @request_env = request.env
  @header_format = Castle::Headers::Format
end

Instance Method Details

#callHash

Serialize HTTP headers

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
35
36
# File 'lib/castle/headers/filter.rb', line 27

def call
  @request_env
    .keys
    .each_with_object({}) do |header_name, acc|
      next unless header_name.match(VALUABLE_HEADERS)

      formatted_name = @header_format.call(header_name)
      acc[formatted_name] = @request_env[header_name].to_s
    end
end