Class: HTTP::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/http/client.rb

Overview

Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, last_effective_uri) ⇒ Response

Returns a new instance of Response.



273
274
275
276
# File 'lib/http/client.rb', line 273

def initialize response, last_effective_uri
  @response           = response
  @last_effective_uri = last_effective_uri
end

Instance Attribute Details

#last_effective_uriObject (readonly)

Returns the value of attribute last_effective_uri.



271
272
273
# File 'lib/http/client.rb', line 271

def last_effective_uri
  @last_effective_uri
end

#responseObject (readonly)

Returns the value of attribute response.



271
272
273
# File 'lib/http/client.rb', line 271

def response
  @response
end

Instance Method Details

#bodyObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/http/client.rb', line 286

def body
  case headers['content-encoding'].to_s.downcase
    when 'gzip'
      gz = Zlib::GzipReader.new(StringIO.new(response.body))
      begin
        gz.read
      ensure
        gz.close
      end
    when 'deflate'
      Zlib.inflate(response.body)
    else
      response.body
  end
end

#codeObject



278
279
280
# File 'lib/http/client.rb', line 278

def code
  response.code.to_i
end

#headersObject



282
283
284
# File 'lib/http/client.rb', line 282

def headers
  @headers ||= Hash[response.each_header.entries]
end

#inspectObject



302
303
304
# File 'lib/http/client.rb', line 302

def inspect
  "#<#{self.class} @code=#{code} @last_effective_uri=#{last_effective_uri}>"
end