Class: VCR::Middleware::Excon::RequestHandler

Inherits:
RequestHandler show all
Includes:
LegacyMethods
Defined in:
lib/vcr/middleware/excon.rb

Overview

Handles a single Excon request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LegacyMethods

#query

Methods inherited from RequestHandler

#handle

Methods included from Logger::Mixin

#log, #request_summary, #response_summary

Constructor Details

#initializeRequestHandler

Returns a new instance of RequestHandler.



55
56
57
58
59
# File 'lib/vcr/middleware/excon.rb', line 55

def initialize
  @request_params       = nil
  @response_body_reader = nil
  @should_record        = false
end

Instance Attribute Details

#request_paramsObject (readonly)

Returns the value of attribute request_params.



91
92
93
# File 'lib/vcr/middleware/excon.rb', line 91

def request_params
  @request_params
end

#response_body_readerObject (readonly)

Returns the value of attribute response_body_reader.



91
92
93
# File 'lib/vcr/middleware/excon.rb', line 91

def response_body_reader
  @response_body_reader
end

Instance Method Details

#after_request(response) ⇒ Object

Performs after_request processing based on the provided response.



74
75
76
77
78
79
80
81
82
# File 'lib/vcr/middleware/excon.rb', line 74

def after_request(response)
  vcr_response = vcr_response_for(response)

  if vcr_response && should_record?
    VCR.record_http_interaction(VCR::HTTPInteraction.new(vcr_request, vcr_response))
  end

  invoke_after_request_hook(vcr_response)
end

#before_request(request_params) ⇒ Object

Performs before_request processing based on the provided request_params.



65
66
67
68
69
# File 'lib/vcr/middleware/excon.rb', line 65

def before_request(request_params)
  @request_params       = request_params
  @response_body_reader = create_response_body_reader
  handle
end

#ensure_response_body_can_be_read_for_error_caseObject



84
85
86
87
88
89
# File 'lib/vcr/middleware/excon.rb', line 84

def ensure_response_body_can_be_read_for_error_case
  # Excon does not invoke the `:response_block` when an error
  # has occurred, so we need to be sure to use the non-streaming
  # body reader.
  @response_body_reader = NonStreamingResponseBodyReader
end