Class: VCR::Middleware::Excon::StreamingResponseBodyReader
- Inherits:
-
Object
- Object
- VCR::Middleware::Excon::StreamingResponseBodyReader
- Defined in:
- lib/vcr/middleware/excon.rb
Overview
Wraps an Excon streaming ‘:response_block`, so that we can accumulate the response as it streams back from the real HTTP server in order to record it.
Instance Method Summary collapse
- #call(chunk, remaining_bytes, total_bytes) ⇒ Object
-
#initialize(response_block) ⇒ StreamingResponseBodyReader
constructor
A new instance of StreamingResponseBodyReader.
-
#read_body_from(response_params) ⇒ Object
Provides a duck-typed interface that matches that of ‘NonStreamingResponseBodyReader`.
Constructor Details
#initialize(response_block) ⇒ StreamingResponseBodyReader
Returns a new instance of StreamingResponseBodyReader.
177 178 179 180 |
# File 'lib/vcr/middleware/excon.rb', line 177 def initialize(response_block) @response_block = response_block @chunks = [] end |
Instance Method Details
#call(chunk, remaining_bytes, total_bytes) ⇒ Object
183 184 185 186 |
# File 'lib/vcr/middleware/excon.rb', line 183 def call(chunk, remaining_bytes, total_bytes) @chunks << chunk @response_block.call(chunk, remaining_bytes, total_bytes) end |
#read_body_from(response_params) ⇒ Object
Provides a duck-typed interface that matches that of ‘NonStreamingResponseBodyReader`. The request handler will use this to get the response body.
193 194 195 196 197 198 199 200 201 202 |
# File 'lib/vcr/middleware/excon.rb', line 193 def read_body_from(response_params) if @chunks.none? # Not sure why, but sometimes the body comes through the params # instead of via the streaming block even when the block was # configured. response_params[:body] else @chunks.join('') end end |