Sha256: c9ca399b99e3859c5abe76144160d68ae70c978a0b8b94a2fdc7ebfa41337682
Contents?: true
Size: 819 Bytes
Versions: 6
Compression:
Stored size: 819 Bytes
Contents
module Rhoconnect class BodyContentTypeParser # Constants # CONTENT_TYPE = 'CONTENT_TYPE'.freeze POST_BODY = 'rack.input'.freeze FORM_INPUT = 'rack.request.form_input'.freeze FORM_HASH = 'rack.request.form_hash'.freeze def initialize(app) @app = app end def call(env) if env['CONTENT_TYPE'] && env['CONTENT_TYPE'].match(/^application\/json/) begin if (body = env[POST_BODY].read).length != 0 env.update(FORM_HASH => JSON.parse(body), FORM_INPUT => env[POST_BODY]) end rescue JSON::ParserError => jpe log jpe.message + jpe.backtrace.join("\n") return [500, {'Content-Type' => 'text/plain'}, ["Server error while processing client data"]] end end @app.call(env) end end end
Version data entries
6 entries across 6 versions & 1 rubygems