Sha256: ab3fdae702d09ec7b2d18fa7952574ff4e8f02b4359839eebd1c0b256872fb72

Contents?: true

Size: 948 Bytes

Versions: 8

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins::Multipart
    module Part
      module_function

      def call(value)
        # take out specialized objects of the way
        if value.respond_to?(:filename) && value.respond_to?(:content_type) && value.respond_to?(:read)
          return [value, value.content_type, value.filename]
        end

        content_type = filename = nil

        if value.is_a?(Hash)
          content_type = value[:content_type]
          filename = value[:filename]
          value = value[:body]
        end

        value = value.open(:binmode => true) if value.is_a?(Pathname)

        if value.is_a?(File)
          filename ||= File.basename(value.path)
          content_type ||= MimeTypeDetector.call(value, filename) || "application/octet-stream"
          [value, content_type, filename]
        else
          [StringIO.new(value.to_s), "text/plain"]
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
httpx-0.13.2 lib/httpx/plugins/multipart/part.rb
httpx-0.13.1 lib/httpx/plugins/multipart/part.rb
httpx-0.13.0 lib/httpx/plugins/multipart/part.rb
httpx-0.12.0 lib/httpx/plugins/multipart/part.rb
httpx-0.11.3 lib/httpx/plugins/multipart/part.rb
httpx-0.11.2 lib/httpx/plugins/multipart/part.rb
httpx-0.11.1 lib/httpx/plugins/multipart/part.rb
httpx-0.11.0 lib/httpx/plugins/multipart/part.rb