Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/net/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def read_line(sock, limit, ignore_eof = false) #:nodoc: internal use only

def read_status_line(sock)
str = read_line(sock, MAX_RESPONSE_HEADER_LENGTH).chop
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
# The version is required. "HTTP 200 OK" used to match with a nil
# version, and keep_alive? then raised NoMethodError (net-http#374).
m = /\AHTTP\/(\d+\.\d+)\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
m.captures
end
Expand Down
15 changes: 15 additions & 0 deletions test/net/http/test_httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,21 @@ def test_uri_equals
assert_not_same uri, response.uri
end

def test_status_line_without_version
io = dummy_io(<<EOS)
HTTP 200 OK
Content-Length: 5
Connection: close

hello
EOS

e = assert_raise(Net::HTTPBadResponse) do
Net::HTTPResponse.read_new(io)
end
assert_match(/wrong status line/, e.message)
end

def test_ensure_zero_space_does_not_regress
io = dummy_io(<<EOS)
HTTP/1.1 200OK
Expand Down