Skip to content

Commit d6729bc

Browse files
hsbtclaude
andcommitted
Require net-protocol 0.3.0 for the response line limit
readuntil(limit:) is released, so the limit no longer has to be probed for at load time and the tests no longer have to omit themselves where it is missing. Depending on it also stops the limit from silently doing nothing on an older net-protocol. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 1729ce8 commit d6729bc

5 files changed

Lines changed: 5 additions & 39 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,3 @@ jobs:
3434
run: rake build
3535
env:
3636
LANG: C
37-
38-
test-net-protocol-head:
39-
name: test (net-protocol master)
40-
runs-on: ubuntu-latest
41-
steps:
42-
- uses: actions/checkout@v7
43-
- name: Set up Ruby
44-
uses: ruby/setup-ruby@v1
45-
with:
46-
ruby-version: ruby
47-
- name: Install dependencies
48-
run: bundle install
49-
env:
50-
BUNDLE_WITHOUT: sig
51-
NET_PROTOCOL_GIT: "true"
52-
- name: Run test
53-
run: rake test
54-
env:
55-
NET_PROTOCOL_GIT: "true"

‎Gemfile‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ gem "rake"
66
gem "test-unit"
77
gem "test-unit-ruby-core"
88

9-
# The response line length limit only takes effect on a net-protocol that
10-
# has Net::BufferedIO#readuntil(limit:). Set NET_PROTOCOL_GIT to exercise it
11-
# before that release reaches rubygems.org.
12-
gem "net-protocol", git: "https://github.com/ruby/net-protocol" if ENV["NET_PROTOCOL_GIT"]
13-
149
group :sig do
1510
gem "rbs"
1611
gem "rdoc"

‎lib/net/http/response.rb‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,10 @@ def read_new(sock) #:nodoc: internal use only
155155
res
156156
end
157157

158-
if defined?(Net::ReadLimitExceeded)
159-
def read_line(sock, limit, ignore_eof = false) #:nodoc: internal use only
160-
sock.readuntil("\n", ignore_eof, limit: limit)
161-
rescue Net::ReadLimitExceeded
162-
raise Net::HTTPBadResponse, 'response line too long'
163-
end
164-
else
165-
# net-protocol without Net::BufferedIO#readuntil limit support
166-
def read_line(sock, limit, ignore_eof = false) #:nodoc: internal use only
167-
sock.readuntil("\n", ignore_eof)
168-
end
158+
def read_line(sock, limit, ignore_eof = false) #:nodoc: internal use only
159+
sock.readuntil("\n", ignore_eof, limit: limit)
160+
rescue Net::ReadLimitExceeded
161+
raise Net::HTTPBadResponse, 'response line too long'
169162
end
170163

171164
private

‎net-http.gemspec‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec|
3535
spec.bindir = "exe"
3636
spec.require_paths = ["lib"]
3737

38+
spec.add_dependency "net-protocol", ">= 0.3.0"
3839
spec.add_dependency "uri", ">= 0.11.1"
3940
end

‎test/net/http/test_httpresponse.rb‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,20 @@ def test_response_header_within_limit
4444
end
4545

4646
def test_status_line_too_long
47-
omit 'requires Net::BufferedIO#readuntil limit support' unless defined?(Net::ReadLimitExceeded)
4847
io = endless_io("HTTP/1.1 200 ")
4948
assert_raise(Net::HTTPBadResponse) do
5049
Net::HTTPResponse.read_new(io)
5150
end
5251
end
5352

5453
def test_response_header_line_too_long
55-
omit 'requires Net::BufferedIO#readuntil limit support' unless defined?(Net::ReadLimitExceeded)
5654
io = endless_io("HTTP/1.1 200 OK\nX-Foo: ")
5755
assert_raise(Net::HTTPBadResponse) do
5856
Net::HTTPResponse.read_new(io)
5957
end
6058
end
6159

6260
def test_chunk_size_line_too_long
63-
omit 'requires Net::BufferedIO#readuntil limit support' unless defined?(Net::ReadLimitExceeded)
6461
io = endless_io("HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n")
6562
res = Net::HTTPResponse.read_new(io)
6663
assert_raise(Net::HTTPBadResponse) do
@@ -71,7 +68,6 @@ def test_chunk_size_line_too_long
7168
end
7269

7370
def test_chunk_trailer_line_too_long
74-
omit 'requires Net::BufferedIO#readuntil limit support' unless defined?(Net::ReadLimitExceeded)
7571
io = endless_io("HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n0\n")
7672
res = Net::HTTPResponse.read_new(io)
7773
assert_raise(Net::HTTPBadResponse) do

0 commit comments

Comments
 (0)