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

#as_json, #close, #concurrency, #http1?, #http2?, #peer, #read_in_background, #reusable?, #start_connection, #synchronize, #to_json, #to_s, #version, #viable?

Constructor Details

#initialize(stream) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
# File 'lib/async/http/protocol/http2/client.rb', line 18

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)


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

def call(request)
  raise ::Protocol::HTTP2::Error, "Connection closed!" if self.closed?
  
  response = create_response
  write_request(response, request)
  read_response(response)
  
  return response
end

#create_responseObject



26
27
28
# File 'lib/async/http/protocol/http2/client.rb', line 26

def create_response
  Response::Stream.create(self, self.next_stream_id).response
end

#read_response(response) ⇒ Object



45
46
47
# File 'lib/async/http/protocol/http2/client.rb', line 45

def read_response(response)
  response.wait
end

#write_request(response, request) ⇒ Object



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

def write_request(response, request)
  response.send_request(request)
end