Sha256: 0cb304722297cc23b91054d5ea07e732ddd094814ce6c69320c871b39037c53a

Contents?: true

Size: 1.53 KB

Versions: 75

Compression:

Stored size: 1.53 KB

Contents

#--
# Copyright (c) 2007-2013 Nick Sieger.
# See the file README.txt included with the distribution for
# software license details.
#++

require 'parts'
require 'securerandom'

module Multipartable
  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
  
  def initialize(path, params, headers={}, boundary = Multipartable.secure_boundary)
    headers = headers.clone # don't want to modify the original variable
    parts_headers = headers.delete(:parts) || {}
    super(path, headers)
    parts = 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
  
  attr :boundary
end

Version data entries

75 entries across 64 versions & 13 rubygems

Version Path
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/multipart-post-2.1.1/lib/multipartable.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/multipart-post-2.1.1/lib/multipartable.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/multipart-post-2.1.1/lib/multipartable.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/multipart-post-2.1.1/lib/multipartable.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/multipart-post-2.1.1/lib/multipartable.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/multipart-post-2.1.1/lib/multipartable.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/multipart-post-2.1.1/lib/multipartable.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/multipart-post-2.1.1/lib/multipartable.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/multipart-post-2.1.1/lib/multipartable.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/multipart-post-2.1.1/lib/multipartable.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/multipart-post-2.1.1/lib/multipartable.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/multipart-post-2.1.1/lib/multipartable.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/multipart-post-2.1.1/lib/multipartable.rb