Class: Aitch::Response::Body
Instance Method Summary collapse
- #deflate? ⇒ Boolean
- #gzip? ⇒ Boolean
-
#initialize(response) ⇒ Body
constructor
A new instance of Body.
- #to_s ⇒ Object
Constructor Details
#initialize(response) ⇒ Body
Returns a new instance of Body.
6 7 8 9 10 |
# File 'lib/aitch/response/body.rb', line 6 def initialize(response) @response = response @body = response.body @encoding = @response["content-encoding"] end |
Instance Method Details
#deflate? ⇒ Boolean
16 17 18 |
# File 'lib/aitch/response/body.rb', line 16 def deflate? @encoding == "deflate" end |
#gzip? ⇒ Boolean
12 13 14 |
# File 'lib/aitch/response/body.rb', line 12 def gzip? @encoding == "gzip" end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/aitch/response/body.rb', line 20 def to_s if gzip? Zlib::GzipReader.new(StringIO.new(@body)).read elsif deflate? Zlib::Inflate.inflate(@body) else @body end end |