Sha256: d2fcec599016e04b73ef2764d869bfc10e5ca474ce69ac56adc7c7abff5130f4

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module Brotli
      class Deflater < Transcoder::Deflater
        def deflate(chunk)
          return unless chunk

          ::Brotli.deflate(chunk)
        end
      end

      module RequestBodyClassMethods
        def initialize_deflater_body(body, encoding)
          return Brotli.encode(body) if encoding == "br"

          super
        end
      end

      module ResponseBodyClassMethods
        def initialize_inflater_by_encoding(encoding, response, **kwargs)
          return Brotli.decode(response, **kwargs) if encoding == "br"

          super
        end
      end

      module_function

      def load_dependencies(*)
        require "brotli"
      end

      def self.extra_options(options)
        options.merge(supported_compression_formats: %w[br] + options.supported_compression_formats)
      end

      def encode(body)
        Deflater.new(body)
      end

      def decode(_response, **)
        ::Brotli.method(:inflate)
      end
    end
    register_plugin :brotli, Brotli
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/plugins/brotli.rb
httpx-1.3.3 lib/httpx/plugins/brotli.rb
httpx-1.3.2 lib/httpx/plugins/brotli.rb
httpx-1.3.1 lib/httpx/plugins/brotli.rb
httpx-1.3.0 lib/httpx/plugins/brotli.rb
httpx-1.2.6 lib/httpx/plugins/brotli.rb
httpx-1.2.4 lib/httpx/plugins/brotli.rb
httpx-1.2.3 lib/httpx/plugins/brotli.rb
httpx-1.2.2 lib/httpx/plugins/brotli.rb
httpx-1.2.1 lib/httpx/plugins/brotli.rb
httpx-1.2.0 lib/httpx/plugins/brotli.rb
httpx-1.1.5 lib/httpx/plugins/brotli.rb
httpx-1.1.4 lib/httpx/plugins/brotli.rb
httpx-1.1.3 lib/httpx/plugins/brotli.rb
httpx-1.1.2 lib/httpx/plugins/brotli.rb
httpx-1.1.1 lib/httpx/plugins/brotli.rb
httpx-1.1.0 lib/httpx/plugins/brotli.rb
httpx-1.0.2 lib/httpx/plugins/brotli.rb
httpx-1.0.1 lib/httpx/plugins/brotli.rb
httpx-1.0.0 lib/httpx/plugins/brotli.rb