Class: VCR::Response

Inherits:
Struct
  • Object
show all
Includes:
Normalizers::Body, Normalizers::Header
Defined in:
lib/vcr/structs.rb

Overview

The response of an HTTPInteraction.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Normalizers::Body

included

Constructor Details

#initialize(*args) ⇒ Response

Returns a new instance of Response.



338
339
340
341
# File 'lib/vcr/structs.rb', line 338

def initialize(*args)
  super(*args)
  self. ||= {}
end

Instance Attribute Details

#adapter_metadataHash

Additional metadata used by a specific VCR adapter.

Returns:

  • (Hash)

    the current value of adapter_metadata



334
335
336
# File 'lib/vcr/structs.rb', line 334

def 
  
end

#bodyString

the response body

Returns:

  • (String)

    the current value of body



334
335
336
# File 'lib/vcr/structs.rb', line 334

def body
  @body
end

#headersHash{String => Array<String>}

the response headers

Returns:

  • (Hash{String => Array<String>})

    the current value of headers



334
335
336
# File 'lib/vcr/structs.rb', line 334

def headers
  @headers
end

#http_versionnil, String

the HTTP version

Returns:

  • (nil, String)

    the current value of http_version



334
335
336
# File 'lib/vcr/structs.rb', line 334

def http_version
  @http_version
end

#statusResponseStatus

the status of the response

Returns:



334
335
336
# File 'lib/vcr/structs.rb', line 334

def status
  @status
end

Class Method Details

.decompress(body, type) ⇒ Object

Decode string compressed with gzip or deflate

Raises:



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/vcr/structs.rb', line 452

def self.decompress(body, type)
  unless HAVE_ZLIB
    warn "VCR: cannot decompress response; Zlib not available"
    return
  end

  case type
  when 'gzip'
    gzip_reader_options = {}
    gzip_reader_options[:encoding] = 'ASCII-8BIT' if ''.respond_to?(:encoding)
    yield Zlib::GzipReader.new(StringIO.new(body),
                               **gzip_reader_options).read
  when 'deflate'
    yield Zlib::Inflate.inflate(body)
  when 'identity', NilClass
    return
  else
    raise Errors::UnknownContentEncodingError, "unknown content encoding: #{type}"
  end
end

.from_hash(hash) ⇒ Response

Constructs a new instance from a hash.

Parameters:

  • hash (Hash)

    the hash to use to construct the instance.

Returns:



363
364
365
366
367
368
369
# File 'lib/vcr/structs.rb', line 363

def self.from_hash(hash)
  new ResponseStatus.from_hash(hash.fetch('status', {})),
      hash['headers'],
      body_from(hash['body']),
      hash['http_version'],
      hash['adapter_metadata']
end

Instance Method Details

#compressed?Boolean

Checks if the type of encoding is one of “gzip” or “deflate”.

Returns:

  • (Boolean)