Skip to content

Commit 406642e

Browse files
committed
Handle nil line.
1 parent 53ae324 commit 406642e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/protocol/http1/connection.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ def read(length)
286286
end
287287

288288
def read_line?
289-
line = @stream.gets(CRLF, @maximum_line_length)
290-
291-
unless line.chomp!(CRLF)
292-
# This basically means that the request line, response line, header, or chunked length line is too long.
293-
raise LineLengthError, "Line too long!"
289+
if line = @stream.gets(CRLF, @maximum_line_length)
290+
unless line.chomp!(CRLF)
291+
# This basically means that the request line, response line, header, or chunked length line is too long.
292+
raise LineLengthError, "Line too long!"
293+
end
294294
end
295295

296296
return line

test/protocol/http1/connection/bad.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,19 @@ def input
145145
end.to raise_exception(Protocol::HTTP1::LineLengthError)
146146
end
147147
end
148+
149+
with "incomplete headers" do
150+
def input
151+
<<~HTTP.gsub("\n", "\r\n")
152+
POST / HTTP/1.1
153+
Host: a.com
154+
HTTP
155+
end
156+
157+
it "should fail to parse the request" do
158+
expect do
159+
server.read_request
160+
end.to raise_exception(EOFError)
161+
end
162+
end
148163
end

0 commit comments

Comments
 (0)