class HTTP::FormData::Multipart

‘multipart/form-data` form data.

def self.generate_boundary

Returns:
  • (String) -

Other tags:
    Api: - public
def self.generate_boundary
  ("-" * 21) << SecureRandom.hex(21)
end

def content_type

Returns:
  • (String) -

Other tags:
    Api: - public
def content_type
  "#{@content_type}; boundary=#{@boundary}"
end

def glue

Returns:
  • (String) -

Other tags:
    Api: - private
def glue
  @glue ||= "--#{@boundary}#{CRLF}"
end

def initialize(data, boundary: self.class.generate_boundary, content_type: DEFAULT_CONTENT_TYPE)

Parameters:
  • content_type (String) -- MIME type for the Content-Type header
  • boundary (String) -- custom boundary string
  • data (Enumerable, Hash, #to_h) -- form data key-value pairs

Other tags:
    Api: - public

Other tags:
    Example: With custom content type -
    Example: Basic form data -
def initialize(data, boundary: self.class.generate_boundary, content_type: DEFAULT_CONTENT_TYPE)
  @boundary     = boundary.to_s.freeze
  @content_type = content_type
  @io = CompositeIO.new(parts(data).flat_map { |part| [glue, part] } << tail)
end

def parts(data)

Returns:
  • (Array) -

Other tags:
    Api: - private
def parts(data)
  FormData.ensure_data(data).flat_map do |name, values|
    Array(values).map { |value| Param.new(name, value) }
  end
end

def tail

Returns:
  • (String) -

Other tags:
    Api: - private
def tail
  @tail ||= "--#{@boundary}--#{CRLF}"
end