Class: Hanami::Middleware::BodyParser Private
- Inherits:
-
Object
- Object
- Hanami::Middleware::BodyParser
- Extended by:
- ClassInterface
- Defined in:
- lib/hanami/middleware/body_parser.rb,
lib/hanami/middleware/body_parser/errors.rb,
lib/hanami/middleware/body_parser/json_parser.rb,
lib/hanami/middleware/body_parser/class_interface.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.
Defined Under Namespace
Modules: ClassInterface Classes: BodyParsingError, InvalidParserError, JsonParser, UnknownParserError
Constant Summary collapse
- CONTENT_TYPE =
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.
'CONTENT_TYPE'.freeze
- MEDIA_TYPE_MATCHER =
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.
/\s*[;,]\s*/.freeze
- RACK_INPUT =
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.
'rack.input'.freeze
- ROUTER_PARAMS =
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.
'router.params'.freeze
- ROUTER_PARSED_BODY =
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.
'router.parsed_body'.freeze
- FALLBACK_KEY =
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.
'_'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object private
-
#initialize(app, parsers) ⇒ BodyParser
constructor
private
A new instance of BodyParser.
Methods included from ClassInterface
Constructor Details
#initialize(app, parsers) ⇒ BodyParser
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.
Returns a new instance of BodyParser.
33 34 35 36 |
# File 'lib/hanami/middleware/body_parser.rb', line 33 def initialize(app, parsers) @app = app @parsers = build_parsers(parsers) end |
Instance Method Details
#call(env) ⇒ Object
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.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hanami/middleware/body_parser.rb', line 38 def call(env) body = env[RACK_INPUT].read return @app.call(env) if body.empty? env[RACK_INPUT].rewind # somebody might try to read this stream if (parser = @parsers[media_type(env)]) env[ROUTER_PARSED_BODY] = parser.parse(body) env[ROUTER_PARAMS] = _symbolize(env[ROUTER_PARSED_BODY]) end @app.call(env) end |