Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error on unexpected EOF. #163

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/http/client.rb
Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/http/client_spec.rb
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions spec/support/example_server.rb
Expand Up @@ -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
Expand Down