Class: Async::HTTP::Protocol::HTTP2::Client

Inherits:
Protocol::HTTP2::Client
  • Object
show all
Includes:
Connection
Defined in:
lib/async/http/protocol/http2/client.rb

Instance Attribute Summary

Attributes included from Connection

#count, #promises, #stream

Instance Method Summary collapse

Methods included from Connection

#connected?, #http1?, #http2?, #multiplex, #peer, #read_in_background, #reusable?, #start_connection, #version, #write_frame

Constructor Details

#initialize(stream) ⇒ Client

Returns a new instance of Client.



33
34
35
36
37
38
39
# File 'lib/async/http/protocol/http2/client.rb', line 33

def initialize(stream)
  @stream = stream
  
  framer = ::Protocol::HTTP2::Framer.new(@stream)
  
  super(framer)
end

Instance Method Details

#call(request) ⇒ Object

Used by the client to send requests to the remote server.

Raises:

  • (::Protocol::HTTP2::Error)


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/async/http/protocol/http2/client.rb', line 56

def call(request)
  raise ::Protocol::HTTP2::Error, "Connection closed!" if self.closed?
  
  @count += 1
  
  response = create_response
  response.send_request(request)
  response.wait
  
  return response
end

#create_responseObject



41
42
43
# File 'lib/async/http/protocol/http2/client.rb', line 41

def create_response
  Response.new(self, self.next_stream_id)
end

#stop_connection(error) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/async/http/protocol/http2/client.rb', line 45

def stop_connection(error)
  super
  
  @streams.each do |id, stream|
    if stream.respond_to?(:stop_connection)
      stream.stop_connection(error)
    end
  end
end