Skip to content

Commit

Permalink
Handle nil line.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 15, 2024
1 parent 53ae324 commit 406642e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ def read(length)
end

def read_line?
line = @stream.gets(CRLF, @maximum_line_length)

unless line.chomp!(CRLF)
# This basically means that the request line, response line, header, or chunked length line is too long.
raise LineLengthError, "Line too long!"
if line = @stream.gets(CRLF, @maximum_line_length)
unless line.chomp!(CRLF)
# This basically means that the request line, response line, header, or chunked length line is too long.
raise LineLengthError, "Line too long!"
end
end

return line
Expand Down
15 changes: 15 additions & 0 deletions test/protocol/http1/connection/bad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,19 @@ def input
end.to raise_exception(Protocol::HTTP1::LineLengthError)
end
end

with "incomplete headers" do
def input
<<~HTTP.gsub("\n", "\r\n")
POST / HTTP/1.1
Host: a.com
HTTP
end

it "should fail to parse the request" do
expect do
server.read_request
end.to raise_exception(EOFError)
end
end
end

0 comments on commit 406642e

Please sign in to comment.