Class: HTTP::FormData::Multipart
- Inherits:
-
Object
- Object
- HTTP::FormData::Multipart
- Defined in:
- lib/http/form_data/multipart.rb,
lib/http/form_data/multipart/param.rb
Overview
multipart/form-data form data.
Defined Under Namespace
Classes: Param
Instance Method Summary collapse
-
#content_length ⇒ Fixnum
Returns form data content size to be used for HTTP request
Content-Lengthheader. -
#content_type ⇒ String
Returns MIME type to be used for HTTP request
Content-Typeheader. -
#initialize(data) ⇒ Multipart
constructor
A new instance of Multipart.
-
#to_s ⇒ String
Returns content to be used for HTTP request body.
Constructor Details
#initialize(data) ⇒ Multipart
Returns a new instance of Multipart.
12 13 14 15 16 |
# File 'lib/http/form_data/multipart.rb', line 12 def initialize(data) @parts = Param.coerce FormData.ensure_hash data @boundary = ("-" * 21) << SecureRandom.hex(21) @content_length = nil end |
Instance Method Details
#content_length ⇒ Fixnum
Returns form data content size to be used for HTTP request
Content-Length header.
36 37 38 39 40 41 42 43 44 |
# File 'lib/http/form_data/multipart.rb', line 36 def content_length unless @content_length @content_length = head.bytesize + tail.bytesize @content_length += @parts.map(&:size).reduce(:+) @content_length += (glue.bytesize * (@parts.count - 1)) end @content_length end |
#content_type ⇒ String
Returns MIME type to be used for HTTP request Content-Type header.
28 29 30 |
# File 'lib/http/form_data/multipart.rb', line 28 def content_type "multipart/form-data; boundary=#{@boundary}" end |
#to_s ⇒ String
Returns content to be used for HTTP request body.
21 22 23 |
# File 'lib/http/form_data/multipart.rb', line 21 def to_s head + @parts.map(&:to_s).join(glue) + tail end |