lib/protocol/http1/body/fixed.rb in protocol-http1-0.14.6 vs lib/protocol/http1/body/fixed.rb in protocol-http1-0.15.0
- old
+ new
@@ -1,9 +1,9 @@
# frozen_string_literal: true
# Released under the MIT License.
-# Copyright, 2019-2022, by Samuel Williams.
+# Copyright, 2019-2023, by Samuel Williams.
require 'protocol/http/body/readable'
module Protocol
module HTTP1
@@ -21,24 +21,27 @@
def empty?
@remaining == 0
end
def close(error = nil)
+ # If we are closing the body without fully reading it, the underlying connection is now in an undefined state.
if @remaining != 0
@stream.close
end
super
end
+ # @raises EOFError if the stream is closed before the expected length is read.
def read
if @remaining > 0
+ # `readpartial` will raise `EOFError` if the stream is closed/finished:
if chunk = @stream.readpartial(@remaining)
@remaining -= chunk.bytesize
return chunk
- else
- raise EOFError, "Stream closed with #{@remaining} bytes remaining!"
+ # else
+ # raise EOFError, "Stream closed with #{@remaining} bytes remaining!"
end
end
end
def join