Skip to content
Closed
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
2 changes: 1 addition & 1 deletion lib/net/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read_new(sock) #:nodoc: internal use only

def read_status_line(sock)
str = sock.readline
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in.match(str) or
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
59 changes: 59 additions & 0 deletions test/net/http/test_httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,65 @@ def test_uri_equals
refute_same uri, response.uri
end

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

hello
EOS

assert_raises Net::HTTPBadResponse do
Net::HTTPResponse.read_new(io)
end
end

def test_allow_trailing_space_after_status
io = dummy_io(<<EOS)
HTTP/1.1 200
Content-Length: 5
Connection: close

hello
EOS

res = Net::HTTPResponse.read_new(io)
assert_equal('1.1', res.http_version)
assert_equal('200', res.code)
assert_equal('', res.message)
end

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

hello
EOS

res = Net::HTTPResponse.read_new(io)
assert_equal('1.1', res.http_version)
assert_equal('200', res.code)
assert_equal('OK', res.message)
end

def test_allow_empty_reason_code
io = dummy_io(<<EOS)
HTTP/1.1 200
Content-Length: 5
Connection: close

hello
EOS

res = Net::HTTPResponse.read_new(io)
assert_equal('1.1', res.http_version)
assert_equal('200', res.code)
assert_equal(nil, res.message)
end

private

def dummy_io(str)
Expand Down