Class: HTTP::FormData::Multipart
- Inherits:
-
Object
- Object
- HTTP::FormData::Multipart
- Includes:
- Readable
- 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 Attribute Summary collapse
-
#boundary ⇒ Object
readonly
Returns the value of attribute boundary.
Class Method Summary collapse
-
.generate_boundary ⇒ String
Generates a string suitable for using as a boundary in multipart form data.
Instance Method Summary collapse
-
#content_type ⇒ String
Returns MIME type to be used for HTTP request
Content-Type
header. -
#initialize(data, boundary: self.class.generate_boundary) ⇒ Multipart
constructor
A new instance of Multipart.
Methods included from Readable
Constructor Details
#initialize(data, boundary: self.class.generate_boundary) ⇒ Multipart
Returns a new instance of Multipart.
18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#boundary ⇒ Object (readonly)
Returns the value of attribute boundary.
15 16 17 |
# File 'lib/http/form_data/multipart.rb', line 15 def boundary @boundary end |
Class Method Details
.generate_boundary ⇒ String
Generates a string suitable for using as a boundary in multipart form data.
29 30 31 |
# File 'lib/http/form_data/multipart.rb', line 29 def self.generate_boundary ("-" * 21) << SecureRandom.hex(21) end |
Instance Method Details
#content_type ⇒ String
Returns MIME type to be used for HTTP request Content-Type
header.
36 37 38 |
# File 'lib/http/form_data/multipart.rb', line 36 def content_type "multipart/form-data; boundary=#{@boundary}" end |