Module: Rack::Multipart
- Defined in:
- lib/rack/multipart.rb,
lib/rack/multipart/parser.rb,
lib/rack/multipart/generator.rb,
lib/rack/multipart/uploaded_file.rb
Overview
A multipart form data parser, adapted from IOWA.
Usually, Rack::Request#POST takes care of calling this.
Defined Under Namespace
Classes: BoundaryTooLongError, EmptyContentError, Generator, MissingInputError, MultipartPartLimitError, MultipartTotalPartLimitError, ParamList, Parser, UploadedFile
Constant Summary collapse
- MULTIPART_BOUNDARY =
"AaB03x"
- Error =
Prefer to use the BoundaryTooLongError class or Rack::BadRequest.
BoundaryTooLongError
- EOL =
"\r\n"
- MULTIPART =
%r|\Amultipart/.*boundary=\"?([^\";,]+)\"?|ni
- MULTIPART_CONTENT_TYPE =
/Content-Type: (.*)#{EOL}/ni
- MULTIPART_CONTENT_DISPOSITION =
/Content-Disposition:(.*)(?=#{EOL}(\S|\z))/ni
- MULTIPART_CONTENT_ID =
/Content-ID:\s*([^#{EOL}]*)/ni
Class Method Summary collapse
- .build_multipart(params, first = true) ⇒ Object
- .extract_multipart(request, params = Rack::Utils.default_query_parser) ⇒ Object
- .parse_multipart(env, params = Rack::Utils.default_query_parser) ⇒ Object
Class Method Details
.build_multipart(params, first = true) ⇒ Object
72 73 74 |
# File 'lib/rack/multipart.rb', line 72 def build_multipart(params, first = true) Generator.new(params, first).dump end |
.extract_multipart(request, params = Rack::Utils.default_query_parser) ⇒ Object
68 69 70 |
# File 'lib/rack/multipart.rb', line 68 def extract_multipart(request, params = Rack::Utils.default_query_parser) parse_multipart(request.env) end |
.parse_multipart(env, params = Rack::Utils.default_query_parser) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rack/multipart.rb', line 48 def parse_multipart(env, params = Rack::Utils.default_query_parser) unless io = env[RACK_INPUT] raise MissingInputError, "Missing input stream!" end 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 |