Skip to content

Commit 715d395

Browse files
author
Felipe Mesquita
committed
keep support for :abort from on_headers by aborting on_body
1 parent 4be2cef commit 715d395

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/ethon/easy/callbacks.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def set_callbacks
3737
# @return [ Proc ] The callback.
3838
def body_write_callback
3939
@body_write_callback ||= proc do |stream, size, num, object|
40-
headers
40+
headers_user_callback_result = headers
4141
result = body(chunk = stream.read_string(size * num))
4242
@response_body << chunk if result == :unyielded
43-
result != :abort ? size * num : -1
43+
(result != :abort && headers_user_callback_result != :abort) ? size * num : -1
4444
end
4545
end
4646

spec/ethon/easy/callbacks_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@
7171
easy.on_headers.clear
7272
easy.on_headers { :abort }
7373
end
74-
let(:header_write_callback) { easy.instance_variable_get(:@header_write_callback) }
75-
74+
let(:body_write_callback) { easy.instance_variable_get(:@body_write_callback) }
75+
# on_headers callbacks are expected to be called exactly one time, once all headers are in.
76+
# We can't abort exactly on receiving the headers, as we might need to follow redirects,
77+
# so we do the next best thing, which is aborting on the first body chunk.
7678
it "returns -1 to indicate abort to libcurl" do
77-
expect(header_write_callback.call(stream, 1, 1, nil)).to eq(-1)
79+
expect(body_write_callback.call(stream, 1, 1, nil)).to eq(-1)
7880
end
7981
end
8082
end

0 commit comments

Comments
 (0)