Class: Hypertube::Utils::Http2ConnectionData

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

Constant Summary collapse

DEFAULT_CONNECT_TIMEOUT_SECONDS =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, timeout = DEFAULT_CONNECT_TIMEOUT_SECONDS) ⇒ Http2ConnectionData

Returns a new instance of Http2ConnectionData.



10
11
12
13
14
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 10

def initialize(hostname, timeout = DEFAULT_CONNECT_TIMEOUT_SECONDS)
  @hostname = hostname
  @timeout = timeout
  @headers = {}
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



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

def hostname
  @hostname
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#add_header(key, value) ⇒ Object



24
25
26
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 24

def add_header(key, value)
  @headers[key.to_s] = value.to_s
end

#add_headers(headers) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 28

def add_headers(headers)
  return if headers.nil?

  headers.each do |key, value|
    add_header(key, value)
  end
end

#connection_typeObject



16
17
18
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 16

def connection_type
  Hypertube::Utils::ConnectionType::HTTP2
end

#headersObject



20
21
22
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 20

def headers
  @headers.dup
end

#serialize_connection_dataObject



36
37
38
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 36

def serialize_connection_data
  [connection_type, 0, 0, 0, 0, 0, 0]
end

#to_canonical_keyObject



44
45
46
47
48
49
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 44

def to_canonical_key
  headers_for_key = serialize_headers_for_key
  return to_s if headers_for_key.empty?

  "#{to_s}|h:#{headers_for_key}"
end

#to_sObject



40
41
42
# File 'lib/hypertube-ruby-sdk/utils/http2_connection_data.rb', line 40

def to_s
  "http2|#{@hostname}"
end