Class: Julewire::Rack::Capture::HeaderSelection

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/rack/capture/header_selection.rb

Constant Summary collapse

SENSITIVE_HEADERS =
%w[
  authorization
  cookie
  proxy-authorization
  set-cookie
  x-api-key
].freeze
SENSITIVE_HEADER_SET =
SENSITIVE_HEADERS.to_h { [it, true] }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selection) ⇒ HeaderSelection

Returns a new instance of HeaderSelection.



27
28
29
# File 'lib/julewire/rack/capture/header_selection.rb', line 27

def initialize(selection)
  @selection = selection
end

Class Method Details

.build(selector) ⇒ Object



17
18
19
20
21
22
# File 'lib/julewire/rack/capture/header_selection.rb', line 17

def build(selector)
  return new(true) if selector == true
  return unless selector

  new(Array(selector).to_h { [normalize_name(it), true] })
end

.normalize_name(name) ⇒ Object



24
# File 'lib/julewire/rack/capture/header_selection.rb', line 24

def normalize_name(name) = name.to_s.tr("_", "-").downcase

Instance Method Details

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/julewire/rack/capture/header_selection.rb', line 31

def include?(name)
  @selection == true ? !SENSITIVE_HEADER_SET.key?(name) : @selection.key?(name)
end