Skip to content

Commit 9a3cef0

Browse files
committed
Fix cassette playback/recording for Typhoeus
- Made sure that on_body callback to record the cassette is invoked first, otherwise if there's a callback before it that returns :abort then the body will not be recorded - Will now invoke on_header and on_body callbacks when playing back the cassette
1 parent 62762b4 commit 9a3cef0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/vcr/library_hooks/typhoeus.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ def vcr_response_from(response)
9393

9494
def collect_chunks(request)
9595
chunks = ''
96-
request.on_body do |body, response|
97-
chunks += body
98-
request.instance_variable_set(:@chunked_body, chunks)
99-
end
96+
request.on_body.unshift(
97+
Proc.new do |body, response|
98+
chunks += body
99+
request.instance_variable_set(:@chunked_body, chunks)
100+
end
101+
)
100102
end
101103

102104
def restore_body_from_chunks(response, request)
@@ -125,6 +127,8 @@ def restore_body_from_chunks(response, request)
125127
::Typhoeus.before do |request|
126128
collect_chunks(request) if request.streaming?
127129
if response = VCR::LibraryHooks::Typhoeus::RequestHandler.new(request).handle
130+
request.on_headers.each { |cb| cb.call(response) }
131+
request.on_body.each { |cb| cb.call(response.body, response) }
128132
request.finish(response)
129133
else
130134
true

0 commit comments

Comments
 (0)