class Async::HTTP::Protocol::HTTP2

def receive_requests(task: Task.current, &block)

def receive_requests(task: Task.current, &block)
	# emits new streams opened by the client
	@controller.on(:stream) do |stream|
		@count += 1
		
		request = Request.new(self, stream)
		body = request.body
		
		stream.on(:headers) do |headers|
			begin
				request.assign_headers(headers)
			rescue
				Async.logger.error(self) {$!}
				
				stream.headers({
					STATUS => "400"
				}, end_stream: true)
			else
				task.async do
					generate_response(request, stream, &block)
				end
			end
		end
		
		stream.on(:data) do |chunk|
			body.write(chunk.to_s) unless chunk.empty?
		end
		
		stream.on(:half_close) do
			# We are no longer receiving any more data frames:
			body.finish
		end
		
		stream.on(:close) do |error|
			if error
				body.stop(EOFError.new(error))
			else
				# In theory, we should have received half_close, so there is no need to:
				# body.finish
			end
		end
	end
	
	start_connection
	@reader.wait
end