Class: Drillbit::Middleware::ParameterParser
- Inherits:
-
Object
- Object
- Drillbit::Middleware::ParameterParser
- Defined in:
- lib/drillbit/middleware/parameter_parser.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ParameterParser
constructor
A new instance of ParameterParser.
Constructor Details
#initialize(app) ⇒ ParameterParser
Returns a new instance of ParameterParser.
11 12 13 |
# File 'lib/drillbit/middleware/parameter_parser.rb', line 11 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/drillbit/middleware/parameter_parser.rb', line 15 def call(env) env['QUERY_STRING'] = underscore_query_string(env['QUERY_STRING']) if env['CONTENT_LENGTH'].to_i.positive? && env['CONTENT_TYPE'] =~ /json/ if env['rack.input'] underscored_input = underscore_request_parameters(env['rack.input']) env['rack.input'] = StringIO.new(underscored_input) env['CONTENT_LENGTH'] = underscored_input.bytesize elsif env['RACK_INPUT'] env['RACK_INPUT'] = underscore_request_parameters(env['RACK_INPUT']) env['CONTENT_LENGTH'] = env['RACK_INPUT'].bytesize end end @app.call(env) rescue JSON::ParserError => _error return Responses::InvalidRequestBody.call(env) end |