Async::HTTPSourceAsyncHTTPProtocolHTTP2Stream

class Stream

Definitions

def prepare_input(length)

Prepare the input stream which will be used for incoming data frames.

Implementation

def prepare_input(length)
	if @input.nil?
		@input = Input.new(self, length)
	else
		raise ArgumentError, "Input body already prepared!"
	end
end

def send_body(body, trailer = nil)

Set the body and begin sending it.

Implementation

def send_body(body, trailer = nil)
	@output = Output.new(self, body, trailer)
	
	@output.start
end

def finish_output(error = nil)

Called when the output terminates normally.

Implementation

def finish_output(error = nil)
	return if self.closed?
	
	trailer = @output&.trailer
	
	@output = nil
	
	if error
		send_reset_stream(::Protocol::HTTP2::Error::INTERNAL_ERROR)
	else
		# Write trailer?
		if trailer&.any?
			send_headers(trailer, ::Protocol::HTTP2::END_STREAM)
		else
			send_data(nil, ::Protocol::HTTP2::END_STREAM)
		end
	end
end

def closed(error)

When the stream transitions to the closed state, this method is called. There are roughly two ways this can happen:

  • A frame is received which causes this stream to enter the closed state. This method will be invoked from the background reader task.
  • A frame is sent which causes this stream to enter the closed state. This method will be invoked from that task. While the input stream is relatively straight forward, the output stream can trigger the second case above

Implementation

def closed(error)
	super
	
	if input = @input
		@input = nil
		input.close_write(error)
	end
	
	if output = @output
		@output = nil
		output.stop(error)
	end
	
	if pool = @pool and @connection
		pool.release(@connection)
	end
	
	return self
end