Class: Castle::Extractors::Headers

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

Overview

used for extraction of cookies and headers from the request

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Headers

Returns a new instance of Headers.



7
8
9
10
11
# File 'lib/castle/extractors/headers.rb', line 7

def initialize(request)
  @request = request
  @request_env = @request.env
  @formatter = HeaderFormatter.new
end

Instance Method Details

#callObject

Serialize HTTP headers



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/castle/extractors/headers.rb', line 14

def call
  @request_env.keys.each_with_object({}) do |header, acc|
    name = @formatter.call(header)

    if Castle.config.whitelisted.include?(name) && !Castle.config.blacklisted.include?(name)
      acc[name] = @request_env[header]
    else
      # When a header is not whitelisted or blacklisted, we're not suppose to send
      # it's value but we should send it's name to indicate it's presence
      acc[name] = true
    end
  end
end