Sha256: c0f9c3cc74ab949121c768e6075e6bc7a090a447011891177c56129067f91d55
Contents?: true
Size: 815 Bytes
Versions: 11
Compression:
Stored size: 815 Bytes
Contents
# encoding: utf-8 module Hyperdrive module Middleware class ParseJSONBody def initialize(app) @app = app end def call(env) req = Rack::Request.new(env) if req.media_type =~ /json$/ begin json_body = MultiJson.load(env['rack.input'].read) env["rack.input"].rewind rescue => e puts "JSONParseError: #{e.message}" raise Hyperdrive::Errors::JSONParseError.new end env['rack.request.form_hash'] ||= {} env['rack.request.form_hash'].merge!(json_body) env['rack.request.form_input'] = Rack::Utils.build_query(env['rack.request.form_hash']) env['rack.input'] = env['rack.request.form_input'] end @app.call(env) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems