Protocol::HTTP3SourceProtocolHTTP3Stream

class Stream

A single HTTP/3 request or response body stream.

Definitions

def initialize(connection, stream_id)

Initialize the stream wrapper for the given connection and native stream identifier.

Implementation

def initialize(connection, stream_id)
	@connection = connection
	@stream_id = stream_id
end

def read_chunk

Read the next available body chunk from the stream.

Implementation

def read_chunk
	@connection.__send__(:read_body_chunk, @stream_id)
end

def write_chunk(chunk)

Write a body chunk to the stream.

Implementation

def write_chunk(chunk)
	@connection.__send__(:write_body_chunk, @stream_id, chunk)
	@connection.send_packets
end

def finish

Finish the stream after all body chunks have been written.

Implementation

def finish
	@connection.__send__(:finish_body, @stream_id)
	@connection.send_packets
end

def reset(error_code = nil)

Reset the stream with the optional HTTP/3 error code.

Implementation

def reset(error_code = nil)
	@connection.__send__(:reset_body, @stream_id, error_code)
	@connection.send_packets
end

def write_body(body)

Write all chunks from the given body to the stream.

Implementation

def write_body(body)
	error = nil
	
	begin
		while chunk = body.read
			write_chunk(chunk)
		end
	rescue => error
		reset
		raise
	ensure
		body.close(error)
		finish unless error
	end
end