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(allowed) ⇒ HeaderSelection

Returns a new instance of HeaderSelection.



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

def initialize(allowed)
  @allowed = allowed
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 unless selector

  allowed = Array(selector).to_h { [normalize_name(it), true] } unless selector == true
  new(allowed)
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)
  @allowed ? @allowed.key?(name) : !SENSITIVE_HEADER_SET.key?(name)
end