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

Version Path
rhosync-2.1.18.beta2 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.18.beta1 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta7 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta6 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta5 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta4 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta3 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta2 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.17.beta1 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.16 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.15 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.14 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.13 lib/rhosync/body_content_type_parser.rb
rhosync-2.1.12 lib/rhosync/body_content_type_parser.rb