lib/protocol/http1/body/remainder.rb in protocol-http1-0.17.0 vs lib/protocol/http1/body/remainder.rb in protocol-http1-0.18.0

- old
+ new

@@ -1,9 +1,9 @@ # frozen_string_literal: true # Released under the MIT License. -# Copyright, 2019-2022, by Samuel Williams. +# Copyright, 2019-2024, by Samuel Williams. require 'protocol/http/body/readable' module Protocol module HTTP1 @@ -12,27 +12,31 @@ BLOCK_SIZE = 1024 * 64 # block_size may be removed in the future. It is better managed by stream. def initialize(stream) @stream = stream + @empty = false end def empty? - @stream.eof? or @stream.closed? + @empty or @stream.closed? end def close(error = nil) # We can't really do anything in this case except close the connection. @stream.close + @empty = true super end # TODO this is a bit less efficient in order to maintain compatibility with `IO`. def read @stream.readpartial(BLOCK_SIZE) rescue EOFError, IOError + @empty = true + # I noticed that in some cases you will get EOFError, and in other cases IOError!? return nil end def call(stream) @@ -43,9 +47,11 @@ stream.flush end def join @stream.read + ensure + @empty = true end def inspect "\#<#{self.class} #{@stream.closed? ? 'closed' : 'open'}>" end