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| request = Request.new request.version = VERSION request.headers = {} request.body = Body.new stream.on(:headers) do |headers| headers.each do |key, value| if key == METHOD request.method = value elsif key == PATH request.path = value elsif key == AUTHORITY request.authority = value else request.headers[key] = value end end end stream.on(:data) do |chunk| request.body.write(chunk.to_s) unless chunk.empty? end stream.on(:half_close) do response = yield request request.body.finish # send response headers = {STATUS => response[0].to_s} headers.update(response[1]) stream.headers(headers, end_stream: false) response[2].each do |chunk| stream.data(chunk, end_stream: false) end stream.data("", end_stream: true) end end @reader.wait end