Class: Shmac::NormalizedHttpHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/shmac/normalized_http_headers.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_headers) ⇒ NormalizedHttpHeaders

Returns a new instance of NormalizedHttpHeaders.



15
16
17
# File 'lib/shmac/normalized_http_headers.rb', line 15

def initialize http_headers
  self.headers = http_headers
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



13
14
15
# File 'lib/shmac/normalized_http_headers.rb', line 13

def headers
  @headers
end

Class Method Details

.from_request_headers(request_headers) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/shmac/normalized_http_headers.rb', line 3

def self.from_request_headers request_headers
  new(
    Hash[
      request_headers.to_h.find_all { |(k, _)|
        k.upcase.start_with?("HTTP_")
      }
    ]
  )
end

Instance Method Details

#normalize_key(key) ⇒ Object



29
30
31
# File 'lib/shmac/normalized_http_headers.rb', line 29

def normalize_key key
  key.to_s.downcase.tr("_", "-").gsub(/\Ahttp-/, "")
end

#to_hObject



19
20
21
# File 'lib/shmac/normalized_http_headers.rb', line 19

def to_h
  headers
end