lib/async/http/protocol/http2.rb in async-http-0.19.0 vs lib/async/http/protocol/http2.rb in async-http-0.20.0

- old
+ new

@@ -62,12 +62,16 @@ end @controller.on(:frame_received) do |frame| Async.logger.debug(self) {"Received frame: #{frame.inspect}"} end + + @count = 0 end + attr :count + # Multiple requests can be processed at the same time. def multiplex @controller.remote_settings[:settings_max_concurrent_streams] end @@ -83,14 +87,14 @@ @reader ||= read_in_background end def read_in_background(task: Task.current) task.async do |nested_task| - buffer = Async::IO::BinaryString.new + nested_task.annotate("#{version} reading data") - while data = @stream.io.read(1024*8, buffer) - @controller << data + while buffer = @stream.read_partial + @controller << buffer end Async.logger.debug(self) {"Connection reset by peer!"} end end @@ -102,10 +106,12 @@ end def receive_requests(task: Task.current, &block) # emits new streams opened by the client @controller.on(:stream) do |stream| + @count += 1 + request = Request.new request.version = self.version request.headers = {} body = Body::Writable.new request.body = body @@ -141,13 +147,13 @@ # send response headers = {STATUS => response.status.to_s} headers.update(response.headers) # puts "Sending headers #{headers}" - if response.body.empty? + if response.body.nil? or response.body.empty? stream.headers(headers, end_stream: true) - response.body.read + response.body.read if response.body else stream.headers(headers, end_stream: false) # puts "Streaming body..." response.body.each do |chunk| @@ -164,10 +170,12 @@ start_connection @reader.wait end def call(request) + @count += 1 + request.version ||= self.version stream = @controller.new_stream headers = { @@ -205,11 +213,12 @@ stream.on(:close) do body.finish end - if request.body.empty? + if request.body.nil? or request.body.empty? stream.headers(headers, end_stream: true) + request.body.read if request.body else stream.headers(headers, end_stream: false) request.body.each do |chunk| stream.data(chunk, end_stream: false)