Sha256: 09d757d68d0df90e918a78c96fb9e13cbadfdd0e110fdde0e7497b5ead76589a

Contents?: true

Size: 532 Bytes

Versions: 12

Compression:

Stored size: 532 Bytes

Contents

module Aitch
  class Response
    class Body
      def initialize(response)
        @response = response
        @body = response.body
        @encoding = @response["content-encoding"]
      end

      def gzip?
        @encoding == "gzip"
      end

      def deflate?
        @encoding == "deflate"
      end

      def to_s
        if gzip?
          Zlib::GzipReader.new(StringIO.new(@body)).read
        elsif deflate?
          Zlib::Inflate.inflate(@body)
        else
          @body
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
aitch-0.5.0 lib/aitch/response/body.rb
aitch-0.4.1 lib/aitch/response/body.rb
aitch-0.4.0 lib/aitch/response/body.rb
aitch-0.3.0 lib/aitch/response/body.rb
aitch-0.2.1 lib/aitch/response/body.rb
aitch-0.2.0 lib/aitch/response/body.rb
aitch-0.1.5 lib/aitch/response/body.rb
aitch-0.1.4 lib/aitch/response/body.rb
aitch-0.1.3 lib/aitch/response/body.rb
aitch-0.1.2 lib/aitch/response/body.rb
aitch-0.1.1 lib/aitch/response/body.rb
aitch-0.1.0 lib/aitch/response/body.rb