Sha256: c945576d18dfd065ad3fdda086dd5041377b3bd87d9f7f2a3af45d4a75d3f52f

Contents?: true

Size: 1004 Bytes

Versions: 45

Compression:

Stored size: 1004 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(File::RDONLY) if Object.const_defined?(:Pathname) && 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), content_type || "text/plain", filename]
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
httpx-0.24.7 lib/httpx/plugins/multipart/part.rb
httpx-0.24.6 lib/httpx/plugins/multipart/part.rb
httpx-0.24.5 lib/httpx/plugins/multipart/part.rb
httpx-0.24.4 lib/httpx/plugins/multipart/part.rb
httpx-0.24.3 lib/httpx/plugins/multipart/part.rb
httpx-0.24.2 lib/httpx/plugins/multipart/part.rb
httpx-0.24.1 lib/httpx/plugins/multipart/part.rb
httpx-0.24.0 lib/httpx/plugins/multipart/part.rb
httpx-0.23.4 lib/httpx/plugins/multipart/part.rb
httpx-0.23.3 lib/httpx/plugins/multipart/part.rb
httpx-0.23.2 lib/httpx/plugins/multipart/part.rb
httpx-0.23.1 lib/httpx/plugins/multipart/part.rb
httpx-0.23.0 lib/httpx/plugins/multipart/part.rb
httpx-0.22.5 lib/httpx/plugins/multipart/part.rb
httpx-0.22.4 lib/httpx/plugins/multipart/part.rb
httpx-0.22.3 lib/httpx/plugins/multipart/part.rb
httpx-0.22.2 lib/httpx/plugins/multipart/part.rb
httpx-0.22.1 lib/httpx/plugins/multipart/part.rb
httpx-0.22.0 lib/httpx/plugins/multipart/part.rb
httpx-0.21.1 lib/httpx/plugins/multipart/part.rb