Sha256: 4c1fb5d934561ec343f92125ec25085b5d7f05f3d53875cf23f8273dbba80f25

Contents?: true

Size: 1.11 KB

Versions: 13

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require "set"

module HTTP
  module Features
    class AutoInflate < Feature
      SUPPORTED_ENCODING = Set.new(%w[deflate gzip x-gzip]).freeze
      private_constant :SUPPORTED_ENCODING

      def wrap_response(response)
        return response unless supported_encoding?(response)

        options = {
          :status        => response.status,
          :version       => response.version,
          :headers       => response.headers,
          :proxy_headers => response.proxy_headers,
          :connection    => response.connection,
          :body          => stream_for(response.connection),
          :request       => response.request
        }

        Response.new(options)
      end

      def stream_for(connection)
        Response::Body.new(Response::Inflater.new(connection))
      end

      private

      def supported_encoding?(response)
        content_encoding = response.headers.get(Headers::CONTENT_ENCODING).first
        content_encoding && SUPPORTED_ENCODING.include?(content_encoding)
      end

      HTTP::Options.register_feature(:auto_inflate, self)
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/features/auto_inflate.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/features/auto_inflate.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/features/auto_inflate.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/http-5.2.0/lib/http/features/auto_inflate.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/features/auto_inflate.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/features/auto_inflate.rb
http-5.2.0 lib/http/features/auto_inflate.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/features/auto_inflate.rb
http-5.1.1 lib/http/features/auto_inflate.rb
http-5.1.0 lib/http/features/auto_inflate.rb
http-5.0.4 lib/http/features/auto_inflate.rb
http-5.0.3 lib/http/features/auto_inflate.rb
http-5.0.2 lib/http/features/auto_inflate.rb