diff --git a/lib/http/client.rb b/lib/http/client.rb index 7643403a..d3bafff3 100644 --- a/lib/http/client.rb +++ b/lib/http/client.rb @@ -129,9 +129,6 @@ def finish_response # Feeds some more data into parser def read_more(size) @parser << @socket.readpartial(size) unless @parser.finished? - true - rescue EOFError - false end end end diff --git a/spec/http/client_spec.rb b/spec/http/client_spec.rb index a2a9c8a9..b5328064 100644 --- a/spec/http/client_spec.rb +++ b/spec/http/client_spec.rb @@ -156,6 +156,11 @@ def simple_response(body, status = 200) client.get("http://127.0.0.1:#{ExampleService::PORT}/").to_s end + it 'fails on unexpected eof' do + expect { client.get("http://127.0.0.1:#{ExampleService::PORT}/eof").to_s } + .to raise_error(IOError) + end + context 'with HEAD request' do it 'does not iterates through body' do expect(client).to_not receive(:readpartial) diff --git a/spec/support/example_server.rb b/spec/support/example_server.rb index 77b4d964..9d508f0a 100644 --- a/spec/support/example_server.rb +++ b/spec/support/example_server.rb @@ -23,6 +23,8 @@ def do_GET(request, response) # rubocop:disable MethodName when '/redirect-302' response.status = 302 response['Location'] = "http://127.0.0.1:#{PORT}/" + when '/eof' + request.instance_variable_get('@socket').close else response.status = 404 end