diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index 8e05ef56..e1e9bb13 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -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 diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb index 7c213f30..18f200b7 100644 --- a/test/net/http/test_httpresponse.rb +++ b/test/net/http/test_httpresponse.rb @@ -876,6 +876,21 @@ def test_uri_equals assert_not_same uri, response.uri end + def test_status_line_without_version + io = dummy_io(<