<commit_before># 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'])
        end
        @app.call(env)
      end
    end
  end
end<commit_msg>rack.request.form_input needs to be set to rack.input for request.params to work properly<commit_after># 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
{'fraction_non_alphanumeric': 0.12374779021803183, 'fraction_numerical': 0.0011785503830288745, 'mean_word_length': 2.0872727272727274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6261521', 'n_tokens_mistral': 530, 'n_tokens_neox': 510, 'n_words': 98}