Sha256: e41fbac301ffc4c9ab20cb0e703b7283ef4574705c7d2ca262ddfca83fd1b107

Contents?: true

Size: 943 Bytes

Versions: 2

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module Multipart
      module FormTranscoder
        module_function

        class Encoder
          extend Forwardable

          def_delegator :@raw, :content_type

          def_delegator :@raw, :to_s

          def_delegator :@raw, :read

          def initialize(form)
            @raw = HTTP::FormData.create(form)
          end

          def bytesize
            @raw.content_length
          end

          def force_encoding(*args)
            @raw.to_s.force_encoding(*args)
          end

          def to_str
            @raw.to_s
          end
        end

        def encode(form)
          Encoder.new(form)
        end
      end

      def self.load_dependencies(*)
        require "http/form_data"
      end

      def self.configure(*)
        Transcoder.register("form", FormTranscoder)
      end
    end
    register_plugin :multipart, Multipart
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
httpx-0.3.1 lib/httpx/plugins/multipart.rb
httpx-0.3.0 lib/httpx/plugins/multipart.rb