Method: H2::Client#initialize

Defined in:
lib/h2/client.rb

#initialize(host: nil, port: 443, url: nil, lazy: true, tls: {}) {|_self| ... } ⇒ H2::Client

create a new h2 client

Parameters:

  • host (String) (defaults to: nil)

    IP address or hostname

  • port (Integer) (defaults to: 443)

    TCP port (default: 443)

  • url (String, URI) (defaults to: nil)

    full URL to parse (optional: existing URI instance)

  • lazy (Boolean) (defaults to: true)

    if true, awaits first stream to initiate connection (default: true)

  • tls (Hash, FalseClass) (defaults to: {})

    TLS options (optional: false do not use TLS)

Options Hash (tls:):

  • :cafile (String)

    path to CA file

Yields:

  • (_self)

Yield Parameters:

  • _self (H2::Client)

    the object that the method was called on

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/h2/client.rb', line 39

def initialize host: nil, port: 443, url: nil, lazy: true, tls: {}
  raise ArgumentError if url.nil? && (host.nil? || port.nil?)

  if url
    url     = URI.parse url unless URI === url
    @host   = url.host
    @port   = url.port
    @scheme = url.scheme
    tls     = false if 'http' == @scheme
  else
    @host = host
    @port = port
    @scheme = tls ? 'https' : 'http'
  end

  @tls       = tls
  @streams   = {}
  @client    = HTTP2::Client.new
  @read_gate = ReadGate.new

  init_blocking
  yield self if block_given?
  bind_events

  connect unless lazy
end