Sha256: 9a3dfab7d79f29f87fad324c7da926d771f785c13c95a22469797dca558dc9e8

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require_relative 'constants'
require_relative 'utils'

require_relative 'multipart/parser'
require_relative 'multipart/generator'

module Rack
  # A multipart form data parser, adapted from IOWA.
  #
  # Usually, Rack::Request#POST takes care of calling this.
  module Multipart
    MULTIPART_BOUNDARY = "AaB03x"

    class << self
      def parse_multipart(env, params = Rack::Utils.default_query_parser)
        io = env[RACK_INPUT]

        if content_length = env['CONTENT_LENGTH']
          content_length = content_length.to_i
        end

        content_type = env['CONTENT_TYPE']

        tempfile = env[RACK_MULTIPART_TEMPFILE_FACTORY] || Parser::TEMPFILE_FACTORY
        bufsize = env[RACK_MULTIPART_BUFFER_SIZE] || Parser::BUFSIZE

        info = Parser.parse(io, content_length, content_type, tempfile, bufsize, params)
        env[RACK_TEMPFILES] = info.tmp_files

        return info.params
      end

      def extract_multipart(request, params = Rack::Utils.default_query_parser)
        parse_multipart(request.env)
      end

      def build_multipart(params, first = true)
        Generator.new(params, first).dump
      end
    end
  end
end

Version data entries

23 entries across 22 versions & 6 rubygems

Version Path
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rack-3.0.11/lib/rack/multipart.rb
rack-3.0.10 lib/rack/multipart.rb
rack-3.0.9.1 lib/rack/multipart.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rack-3.0.9/lib/rack/multipart.rb
rack-3.0.9 lib/rack/multipart.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rack-3.0.8/lib/rack/multipart.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rack-3.0.7/lib/rack/multipart.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rack-3.0.8/lib/rack/multipart.rb
rack-3.0.8 lib/rack/multipart.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rack-3.0.7/lib/rack/multipart.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rack-3.0.7/lib/rack/multipart.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rack-3.0.7/lib/rack/multipart.rb
rack-3.0.7 lib/rack/multipart.rb
rack-3.0.4.2 lib/rack/multipart.rb
rack-3.0.4.1 lib/rack/multipart.rb
rack-3.0.4 lib/rack/multipart.rb
rack-3.0.3 lib/rack/multipart.rb
rack-3.0.2 lib/rack/multipart.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/rack-3.0.1/lib/rack/multipart.rb
rack-3.0.1 lib/rack/multipart.rb