httpx/test/support/request_inspector.rb
HoneyryderChuck 7169f6aaaf stream plugin: allow partial buffering of the response when calling things other than #each
this allows calling #status or #headers on a stream response, without buffering the whole response, as it's happening now; this will only work for methods which do not rely on the whole payload to be available, but that should be ok for the stream plugin usage

Fixes https://github.com/janko/down/issues/98
2025-04-03 17:51:02 +01:00

32 lines
631 B
Ruby

# frozen_string_literal: true
module RequestInspector
module InstanceMethods
attr_reader :calls, :total_responses
def initialize(*args)
super
# we're comparing against max-retries + 1, because the calls increment will happen
# also in the last call, where the request is not going to be retried.
@calls = -1
@total_responses = []
end
def reset
@calls = -1
@total_responses.clear
end
private
def fetch_response(*)
response = super
if response
@calls += 1
@total_responses << response
end
response
end
end
end