Skip to content

Require an HTTP version on the response status line - #381

Open
adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/status-line-requires-version
Open

adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/status-line-requires-version

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #374.

read_status_line treated the version as optional, so HTTP 200 OK was accepted with http_version nil. end_transport stored that nil, and keep_alive? then evaluated nil <= "1.0", raising NoMethodError. The nil stayed on the client, so the next request was written as GET /path HTTP/ with no version.

The version is now required. HTTP 200 OK raises Net::HTTPBadResponse (wrong status line) before the version is stored. HTTP/1.0 and HTTP/1.1 are unchanged, including a status line with an empty reason.

Before the change, a response of HTTP 200 OK raised NoMethodError: undefined method '<=' for nil. After it, the same response raises Net::HTTPBadResponse, and a second request on that client is still GET /b HTTP/1.1.

ruby -Ilib:test/lib -rhelper test/net/http/test_httpresponse.rb: 50 tests, 110 assertions, 0 failures.

"HTTP 200 OK" used to be accepted with a nil version, and the next
keep-alive check raised NoMethodError.
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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A status line without an HTTP version is accepted, then crashes keep_alive? and poisons the client's request framing

1 participant