Module: Shaf::HttpHeader

Defined in:
lib/shaf/helpers/http_header.rb

Instance Method Summary collapse

Instance Method Details

#request_header(header) ⇒ Object



22
23
24
# File 'lib/shaf/helpers/http_header.rb', line 22

def request_header(header)
  request_headers[header.to_s.upcase]
end

#request_headersObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/shaf/helpers/http_header.rb', line 5

def request_headers
  unless respond_to? :request
    log.error <<~ERROR


      Classes including the HttpHeader module must respond to #request
      HttpHeader#request_headers called from #{self}.
    ERROR
    raise Errors::ServerError, 'Server bug'
  end

  request.env.each_with_object({}) do |(key, value), headers|
    next unless key =~ /^HTTP_/
    headers[key[5..-1].tr('_', '-')] = value
  end
end