From 2eb9e251e55a7353247ed369d5d131507b8f36a3 Mon Sep 17 00:00:00 2001 From: Aditya <152765789+adityawrk@users.noreply.github.com> Date: Sun, 29 Nov 2026 07:51:59 +0530 Subject: [PATCH 1/2] Test that a status line without a version is rejected "HTTP 200 OK" used to be accepted with a nil version, and the next keep-alive check raised NoMethodError. --- test/net/http/test_httpresponse.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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(< Date: Sun, 29 Nov 2026 07:51:59 +0530 Subject: [PATCH 2/2] Require an HTTP version on the response status line A status line such as "HTTP 200 OK" matched with a nil version. keep_alive? then evaluated nil <= "1.0", and the client kept that nil and wrote later requests as "HTTP/" with no version. --- lib/net/http/response.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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