Class: Hanami::Middleware::BodyParser::FormParser Private

Inherits:
Parser
  • Object
show all
Defined in:
lib/hanami/middleware/body_parser/form_parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1

Constant Summary collapse

MEDIA_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1

["multipart/form-data"].freeze

Instance Attribute Summary

Attributes inherited from Parser

#media_types

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#initialize

Constructor Details

This class inherits a constructor from Hanami::Middleware::BodyParser::Parser

Class Method Details

.media_typesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1



17
# File 'lib/hanami/middleware/body_parser/form_parser.rb', line 17

def self.media_types = MEDIA_TYPES

Instance Method Details

#parse(env) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a multipart body payload (form file uploading)

Returns:

  • (Hash)

    the parsed multipart body

Raises:

Since:

  • 2.0.1



27
28
29
30
31
32
33
# File 'lib/hanami/middleware/body_parser/form_parser.rb', line 27

def parse(*, env)
  # Rewind to ensure successful parsing (required for Rack 3's `.parse_multipart`).
  env[::Rack::RACK_INPUT].rewind if env[::Rack::RACK_INPUT].respond_to?(:rewind)
  ::Rack::Multipart.parse_multipart(env)
rescue StandardError => exception
  raise BodyParsingError.new(exception.message)
end