Class: NetHttp2::Client

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/net-http2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#callback_events, #emit, #on

Constructor Details

#initialize(url, options = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/net-http2/client.rb', line 19

def initialize(url, options={})
  @uri             = URI.parse(url)
  @connect_timeout = options[:connect_timeout] || 60
  @ssl_context     = add_npn_to_context(options[:ssl_context] || OpenSSL::SSL::SSLContext.new)

  PROXY_SETTINGS_KEYS.each do |key|
    instance_variable_set("@#{key}", options[key]) if options[key]
  end

  @is_ssl = (@uri.scheme == 'https')

  @mutex = Mutex.new
  init_vars
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



17
18
19
# File 'lib/net-http2/client.rb', line 17

def uri
  @uri
end

Instance Method Details

#call(method, path, options = {}) ⇒ Object



34
35
36
37
38
# File 'lib/net-http2/client.rb', line 34

def call(method, path, options={})
  request = prepare_request(method, path, options)
  ensure_open
  new_stream.call_with request
end

#call_async(request) ⇒ Object



40
41
42
43
44
# File 'lib/net-http2/client.rb', line 40

def call_async(request)
  ensure_open
  stream = new_monitored_stream_for request
  stream.async_call_with request
end

#closeObject



54
55
56
57
# File 'lib/net-http2/client.rb', line 54

def close
  exit_thread(@socket_thread)
  init_vars
end

#join(timeout: nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/net-http2/client.rb', line 59

def join(timeout: nil)
  starting_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  while !@streams.empty? do
    raise AsyncRequestTimeout if timeout && Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting_time > timeout
    sleep 0.05
  end
end

#prepare_request(method, path, options = {}) ⇒ Object



46
47
48
# File 'lib/net-http2/client.rb', line 46

def prepare_request(method, path, options={})
  NetHttp2::Request.new(method, @uri, path, options)
end

#remote_settingsObject



67
68
69
# File 'lib/net-http2/client.rb', line 67

def remote_settings
  h2.remote_settings
end

#ssl?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/net-http2/client.rb', line 50

def ssl?
  @is_ssl
end

#stream_countObject



71
72
73
# File 'lib/net-http2/client.rb', line 71

def stream_count
  @streams.length
end