class Async::HTTP::Protocol::HTTP2

def send_request(authority, method, path, headers = {}, body = nil)

def send_request(authority, method, path, headers = {}, body = nil)
	stream = @controller.new_stream
	
	internal_headers = {
		SCHEME => HTTPS,
		METHOD => method,
		PATH => path,
		AUTHORITY => authority,
	}.merge(headers)
	
	stream.headers(internal_headers, end_stream: body.nil?)
	
	if body
		body.each do |chunk|
			stream.data(chunk, end_stream: false)
		end
		
		stream.data("", end_stream: true)
	end
	
	finished = Async::Notification.new
	
	response = Response.new
	response.version = RESPONSE_VERSION
	response.headers = {}
	response.body = Body.new
	
	stream.on(:headers) do |headers|
		# Async.logger.debug(self) {"Stream headers: #{headers.inspect}"}
		
		headers.each do |key, value|
			if key == STATUS
				response.status = value.to_i
			elsif key == REASON
				response.reason = value
			else
				response.headers[key] = value
			end
		end
		
		finished.signal
	end
	
	stream.on(:data) do |chunk|
		Async.logger.debug(self) {"Stream data: #{chunk.inspect}"}
		response.body.write(chunk.to_s) unless chunk.empty?
	end
	
	stream.on(:half_close) do
		Async.logger.debug(self) {"Stream half-closed."}
	end
	
	stream.on(:close) do
		Async.logger.debug(self) {"Stream closed, sending signal."}
		# TODO should we prefer response.close?
		response.body.close
	end
	
	@stream.flush
	
	# Async.logger.debug(self) {"Stream flushed, waiting for signal."}
	finished.wait
	
	# Async.logger.debug(self) {"Stream finished: #{response.inspect}"}
	return response
end