Sha256: 38b7b4d8b61d060061db0f2712522a377e2255673f1ef9449095fd459b2d3bed
Contents?: true
Size: 816 Bytes
Versions: 15
Compression:
Stored size: 816 Bytes
Contents
module Rhosync 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
15 entries across 15 versions & 1 rubygems