Skip to content

Commit

Permalink
ensure wire always contains a full frame
Browse files Browse the repository at this point in the history
  • Loading branch information
maruth-stripe committed Nov 6, 2023
1 parent d2f6815 commit de36239
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/protocol/http2/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def self.parse_header(buffer)
end

def read_header(stream)
if buffer = stream.read(9) and buffer.bytesize == 9
if buffer = stream.peek(9) and buffer.bytesize == 9
@length, @type, @flags, @stream_id = Frame.parse_header(buffer)
# puts "read_header: #{@length} #{@type} #{@flags} #{@stream_id}"
else
Expand All @@ -155,8 +155,9 @@ def read_header(stream)
end

def read_payload(stream)
if payload = stream.read(@length) and payload.bytesize == @length
@payload = payload
length_with_header = 9 + @length
if full_frame = stream.read(length_with_header) and full_frame.bytesize == length_with_header
@payload = full_frame[9..]
else
raise EOFError, "Could not read frame payload!"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/http2/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def write_frame(frame)
end

def read_header
if buffer = @stream.read(9)
if buffer = @stream.peek(9)
if buffer.bytesize == 9
return Frame.parse_header(buffer)
end
Expand Down

0 comments on commit de36239

Please sign in to comment.