Class: Hypertube::Utils::ConnectionData

Inherits:
Object
  • Object
show all
Defined in:
lib/hypertube-ruby-sdk/utils/connection_data.rb

Constant Summary collapse

THREAD_LOCAL_HEADERS_KEY =
:hypertube_connection_data_thread_local_headers

Instance Method Summary collapse

Constructor Details

#initializeConnectionData

Returns a new instance of ConnectionData.



8
9
10
# File 'lib/hypertube-ruby-sdk/utils/connection_data.rb', line 8

def initialize
  @headers = {}
end

Instance Method Details

#get_headersObject Also known as: headers



12
13
14
15
16
17
18
# File 'lib/hypertube-ruby-sdk/utils/connection_data.rb', line 12

def get_headers
  combined = @headers.dup
  thread_local_headers.each do |key, value|
    combined[key] = value
  end
  combined
end

#get_thread_local_headersObject



30
31
32
# File 'lib/hypertube-ruby-sdk/utils/connection_data.rb', line 30

def get_thread_local_headers
  (Thread.current[THREAD_LOCAL_HEADERS_KEY] || {}).dup
end

#set_headers(headers) ⇒ Object



22
23
24
# File 'lib/hypertube-ruby-sdk/utils/connection_data.rb', line 22

def set_headers(headers)
  @headers = normalize_headers(headers)
end

#set_thread_local_headers(headers) ⇒ Object



26
27
28
# File 'lib/hypertube-ruby-sdk/utils/connection_data.rb', line 26

def set_thread_local_headers(headers)
  Thread.current[THREAD_LOCAL_HEADERS_KEY] = normalize_headers(headers)
end

#to_canonical_keyObject



34
35
36
37
38
39
# File 'lib/hypertube-ruby-sdk/utils/connection_data.rb', line 34

def to_canonical_key
  key = to_s
  return key if get_headers.empty?

  "#{key}|h:#{serialize_headers_for_key}"
end