Sha256: 195edf3b67595022009cf39ffeeedf9e297499e2bd8c90ff8de3c86651e19754
Contents?: true
Size: 674 Bytes
Versions: 35
Compression:
Stored size: 674 Bytes
Contents
#!/usr/bin/env ruby require 'rack' module Rack class JsonParamsParser < Struct.new(:app) def call(env) if env['rack.input'] and not input_parsed?(env) and type_match?(env) env['rack.request.form_input'] = env['rack.input'] data = env['rack.input'].read env['rack.input'].rewind env['rack.request.form_hash'] = data.empty? ? {} : Oj.load(data) end app.call(env) end def input_parsed? env env['rack.request.form_input'].eql? env['rack.input'] end def type_match? env type = env['CONTENT_TYPE'] and type.split(/\s*[;,]\s*/, 2).first.downcase == 'application/json' end end end
Version data entries
35 entries across 35 versions & 1 rubygems