class Client < ::Protocol::HTTP2::Client

Inherits from
::Protocol::HTTP2::Client
Includes
Connection: #synchronize, #write_frame, #write_frames, #to_s, #as_json, #to_json, #http1?, #http2?, #start_connection, #close, #close_if_drained!, #read_in_background, #peer, #concurrency, #viable?, #reusable?, #version

An HTTP/2 client connection that sends requests and reads responses.

Definitions

def initialize(stream)

Initialize the HTTP/2 client with an IO stream.

Signature

parameter stream IO::Stream

The underlying stream.

Implementation

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

def create_response

Create a new response stream for the next request.

Signature

returns Response

The response object to be populated.

Implementation

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

def call(request)

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

Implementation

def call(request)
	# The remote peer has sent a GOAWAY frame, so it will not process any new streams on this connection. The request has not been sent yet, so it is safe to retry it on a new connection, even if it is not idempotent. This is checked first, because a connection with no streams left to drain is closed by the GOAWAY itself.
	raise ::Protocol::HTTP::RefusedError, "Connection is going away!" if self.goaway_received?
	
	# The connection can close after being acquired from the pool. No stream has been created yet, so the request has not been written and is safe to retry.
	raise ::Protocol::HTTP::RefusedError, "Connection closed!" if self.closed?
	
	response = create_response
	write_request(response, request)
	read_response(response)
	
	return response
end

def write_request(response, request)

Write a request to the remote server via the given response stream.

Signature

parameter response Response

The response stream to write through.

parameter request Protocol::HTTP::Request

The request to send.

Implementation

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

def read_response(response)

Wait for the response headers to arrive.

Signature

parameter response Response

The response to wait on.

Implementation

def read_response(response)
	response.wait
end