Skip to content

Commit

Permalink
Minor improvements to documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 5, 2024
1 parent 7330bc6 commit 93df4e7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/protocol/http1/body/chunked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def read
if length == 0
read_trailer

# The final chunk has been read and the stream is now closed:
@stream = nil
@finished = true

Expand All @@ -75,6 +76,7 @@ def read
return chunk
end

# If the stream has been closed before we have read the final chunk, raise an error:
raise EOFError, "Stream closed before expected length was read!"
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/protocol/http1/body/fixed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Body
class Fixed < HTTP::Body::Readable
def initialize(stream, length)
@stream = stream

@length = length
@remaining = length
end
Expand Down Expand Up @@ -39,14 +40,15 @@ def close(error = nil)
def read
if @remaining > 0
if @stream
# `readpartial` will raise `EOFError` if the stream is closed/finished:
# `readpartial` will raise `EOFError` if the stream is finished, or `IOError` if the stream is closed.
if chunk = @stream.readpartial(@remaining)
@remaining -= chunk.bytesize

return chunk
end
end

# If the stream has been closed before we have read the expected length, raise an error:
raise EOFError, "Stream closed before expected length was read!"
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/protocol/http1/body/remainder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module Protocol
module HTTP1
module Body
# A body that reads all remaining data from the stream.
class Remainder < HTTP::Body::Readable
BLOCK_SIZE = 1024 * 64

Expand All @@ -22,8 +23,8 @@ def empty?

def close(error = nil)
if @stream
@stream.close_read
# We can't really do anything in this case except close the connection.
@stream.close_read
@stream = nil
end

Expand Down

0 comments on commit 93df4e7

Please sign in to comment.