Sha256: 333676ad049af80b6b6f175cde35392b9aad3e761a24ecfc8d848de0058e6691

Contents?: true

Size: 562 Bytes

Versions: 3

Compression:

Stored size: 562 Bytes

Contents

# frozen_string_literal: true
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

3 entries across 3 versions & 1 rubygems

Version Path
aitch-1.0.2 lib/aitch/response/body.rb
aitch-1.0.1 lib/aitch/response/body.rb
aitch-1.0.0 lib/aitch/response/body.rb