Class: Rsodx::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/rsodx/headers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Headers

Returns a new instance of Headers.



5
6
7
8
9
10
11
12
# File 'lib/rsodx/headers.rb', line 5

def initialize(request)
  @headers = request.env.each_with_object({}) do |(k, v), memo|
    if k.start_with?("HTTP_")
      key = k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')
      memo[key] = v
    end
  end
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/rsodx/headers.rb', line 3

def headers
  @headers
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/rsodx/headers.rb', line 14

def [](key)
  headers[key]
end

#authorizationObject



18
19
20
# File 'lib/rsodx/headers.rb', line 18

def authorization
  headers["Authorization"]
end

#bearer_tokenObject



22
23
24
25
# File 'lib/rsodx/headers.rb', line 22

def bearer_token
  return nil unless authorization&.start_with?("Bearer ")
  authorization.sub("Bearer ", "")
end

#to_hObject



27
28
29
# File 'lib/rsodx/headers.rb', line 27

def to_h
  headers
end