Module: Net::WebMockHTTPResponse

Defined in:
lib/webmock/http_lib_adapters/net_http_response.rb

Instance Method Summary collapse

Instance Method Details

#read_body(dest = nil, &block) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/webmock/http_lib_adapters/net_http_response.rb', line 17

def read_body(dest = nil, &block)
  if !(defined?(@__read_body_previously_called).nil?) && @__read_body_previously_called
    return super
  end
  return @body if dest.nil? && block.nil?
  raise ArgumentError.new("both arg and block given for HTTP method") if dest && block
  return nil if @body.nil?

  dest ||= ::Net::ReadAdapter.new(block)
  dest << @body.dup
  @body = dest
ensure
  # allow subsequent calls to #read_body to proceed as normal, without our hack...
  @__read_body_previously_called = true
end