Class: Rest::Wrappers::NetHttpPersistentResponseWrapper

Inherits:
BaseResponseWrapper show all
Defined in:
lib/rest/wrappers/net_http_persistent_wrapper.rb

Instance Attribute Summary

Attributes inherited from BaseResponseWrapper

#tries

Instance Method Summary collapse

Methods inherited from BaseResponseWrapper

#headers

Constructor Details

#initialize(response) ⇒ NetHttpPersistentResponseWrapper

Returns a new instance of NetHttpPersistentResponseWrapper.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rest/wrappers/net_http_persistent_wrapper.rb', line 14

def initialize(response)
  @response = response

  if response.header['content-encoding'].eql?('gzip')
    Rest.logger.debug 'GZIPPED'

    if response.body
      sio = StringIO.new(response.body)
      gz = Zlib::GzipReader.new(sio)
      page = gz.read()
      @body = page
    else
      @body = nil
    end

  end
end

Instance Method Details

#bodyObject



36
37
38
# File 'lib/rest/wrappers/net_http_persistent_wrapper.rb', line 36

def body
  @body || @response.body
end

#body_rawObject

In case for some reason you want the unencoded body



41
42
43
# File 'lib/rest/wrappers/net_http_persistent_wrapper.rb', line 41

def body_raw
  @response.body
end

#codeObject



32
33
34
# File 'lib/rest/wrappers/net_http_persistent_wrapper.rb', line 32

def code
  @response.code.to_i
end

#headers_origObject



45
46
47
# File 'lib/rest/wrappers/net_http_persistent_wrapper.rb', line 45

def headers_orig
  @response.to_hash
end