class Shmac::NormalizedHttpHeaders

Attributes

headers[R]

Public Class Methods

from_request_headers(request_headers) click to toggle source
# 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
new(http_headers) click to toggle source
# File lib/shmac/normalized_http_headers.rb, line 15
def initialize http_headers
  self.headers = http_headers
end

Public Instance Methods

headers=(http_headers) click to toggle source
# File lib/shmac/normalized_http_headers.rb, line 23
def headers= http_headers
  @headers = http_headers.each_with_object({}) { |(k,v), memo|
    memo[normalize_key(k)] = Array(v).join(",")
  }
end
normalize_key(key) click to toggle source
# File lib/shmac/normalized_http_headers.rb, line 29
def normalize_key key
  key.to_s.downcase.tr("_", "-").gsub(/\Ahttp-/, "")
end
to_h() click to toggle source
# File lib/shmac/normalized_http_headers.rb, line 19
def to_h
  headers
end