Class: Protocol::Multipart::FormData

Inherits:
Mixed
  • Object
show all
Includes:
Escape
Defined in:
lib/protocol/multipart/form_data.rb

Overview

FormData class for handling multipart/form-data format used in HTTP forms. Extends Mixed to provide specific support for form fields with names and values.

Instance Attribute Summary

Attributes inherited from Mixed

#The boundary string used to separate parts., #The parts of the body., #boundary, #parts

Attributes inherited from Part

#headers

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Escape

#escape_field_name, #unescape_field_name

Methods inherited from Mixed

#call, #initialize

Methods inherited from Part

#The headers as name/value pairs.=, #call, #initialize

Constructor Details

This class inherits a constructor from Protocol::Multipart::Mixed

Class Method Details

.mime_typeObject

Returns the MIME type for form data.



20
21
22
# File 'lib/protocol/multipart/form_data.rb', line 20

def self.mime_type
  "multipart/form-data"
end

Instance Method Details

#add_field(name, value, headers = {}) ⇒ Object

Adds a form field to the multipart form data.



30
31
32
33
34
35
36
37
38
# File 'lib/protocol/multipart/form_data.rb', line 30

def add_field(name, value, headers = {})
  headers = headers.merge(
    "content-disposition" => "form-data; name=\"#{escape_field_name name}\""
  )
  
  StringPart.new(headers, value).tap do |part|
    @parts << part
  end
end