Module: Multipart::Post::Multipartable
- Included in:
- Net::HTTP::Post::Multipart, Net::HTTP::Put::Multipart
- Defined in:
- lib/multipart/post/multipartable.rb
Instance Attribute Summary collapse
-
#boundary ⇒ Object
readonly
Returns the value of attribute boundary.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#boundary ⇒ Object (readonly)
Returns the value of attribute boundary.
61 62 63 |
# File 'lib/multipart/post/multipartable.rb', line 61 def boundary @boundary end |
Class Method Details
.secure_boundary ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/multipart/post/multipartable.rb', line 24 def self.secure_boundary # https://tools.ietf.org/html/rfc7230 # tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" # / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" # / DIGIT / ALPHA # https://tools.ietf.org/html/rfc2046 # bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" / # "+" / "_" / "," / "-" / "." / # "/" / ":" / "=" / "?" "--#{SecureRandom.uuid}" end |
Instance Method Details
#initialize(path, params, headers = {}, boundary = Multipartable.secure_boundary) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/multipart/post/multipartable.rb', line 38 def initialize(path, params, headers={}, boundary = Multipartable.secure_boundary) headers = headers.clone # don't want to modify the original variable parts_headers = symbolize_keys(headers.delete(:parts) || {}) super(path, headers) parts = symbolize_keys(params).map do |k,v| case v when Array v.map {|item| Parts::Part.new(boundary, k, item, parts_headers[k]) } else Parts::Part.new(boundary, k, v, parts_headers[k]) end end.flatten parts << Parts::EpiloguePart.new(boundary) ios = parts.map {|p| p.to_io } self.set_content_type(headers["Content-Type"] || "multipart/form-data", { "boundary" => boundary }) self.content_length = parts.inject(0) {|sum,i| sum + i.length } self.body_stream = CompositeReadIO.new(*ios) @boundary = boundary end |