Class: Protocol::Multipart::FormData

Inherits:
Mixed
  • Object
show all
Includes:
Escape
Defined in:
lib/protocol/multipart/form_data.rb,
lib/protocol/multipart/form_data/parser.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.

Defined Under Namespace

Classes: Parser, Upload

Constant Summary collapse

MAXIMUM_FIELD_SIZE =

The default maximum size of a buffered form field.

2 * 1024 * 1024
MAXIMUM_UPLOAD_SIZE =

The default maximum size of a streamed file upload.

128 * 1024 * 1024
MAXIMUM_TOTAL_SIZE =

The default maximum combined size of all form fields and file uploads.

256 * 1024 * 1024

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.



84
85
86
# File 'lib/protocol/multipart/form_data.rb', line 84

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.



94
95
96
97
98
99
100
101
102
# File 'lib/protocol/multipart/form_data.rb', line 94

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