class HTTP::FormData::Multipart
`multipart/form-data` form data.
Attributes
boundary[R]
Public Class Methods
generate_boundary()
click to toggle source
Generates a string suitable for using as a boundary in multipart form data.
@return [String]
# File lib/http/form_data/multipart.rb, line 29 def self.generate_boundary ("-" * 21) << SecureRandom.hex(21) end
new(data, boundary: self.class.generate_boundary)
click to toggle source
@param [#to_h, Hash] data form data key-value Hash
# File lib/http/form_data/multipart.rb, line 18 def initialize(data, boundary: self.class.generate_boundary) parts = Param.coerce FormData.ensure_hash data @boundary = boundary.to_s.freeze @io = CompositeIO.new [*parts.flat_map { |part| [glue, part] }, tail] end
Public Instance Methods
content_type()
click to toggle source
Returns MIME type to be used for HTTP
request `Content-Type` header.
@return [String]
# File lib/http/form_data/multipart.rb, line 36 def content_type "multipart/form-data; boundary=#{@boundary}" end
Private Instance Methods
glue()
click to toggle source
@return [String]
# File lib/http/form_data/multipart.rb, line 49 def glue @glue ||= "--#{@boundary}#{CRLF}" end
tail()
click to toggle source
@return [String]
# File lib/http/form_data/multipart.rb, line 54 def tail @tail ||= "--#{@boundary}--#{CRLF}" end