<commit_before>module ShamRack

  module HTTP

    module Extensions

      attr_accessor :rack_app

      def start
        yield self
      end

      def request(req, body = nil)
        env = default_env
        env.merge!(path_env(req.path))
        env.merge!(method_env(req))
        env.merge!(header_env(req))
        env.merge!(io_env(req, body))
        response = build_response(@rack_app.call(env))
        yield response if block_given?
        return response
      end

      private

      def default_env
        {
          "SCRIPT_NAME" => "",
          "SERVER_NAME" => @address,
          "SERVER_PORT" => @port.to_s,   
          "rack.version" => [0,1],
          "rack.url_scheme" => "http",
          "rack.multithread" => true,
          "rack.multiprocess" => true,
          "rack.run_once" => false
        }
      end

      def method_env(request)
        {
          "REQUEST_METHOD" => request.method
        }
      end

      def io_env(request, body)
        raise(ArgumentError, "both request.body and body argument were provided") if (request.body && body)
        body ||= request.body || ""
        { 
          "rack.input" => StringIO.new(body),
          "rack.errors" => $stderr
        }
      end

      def path_env(path)
        uri = URI.parse(path)
        {
          "PATH_INFO" => uri.path,
          "QUERY_STRING" => (uri.query || ""),
        }
      end<commit_msg>fix a incompatibility with rest-client 1.2.0<commit_after>module ShamRack

  module HTTP

    module Extensions

      attr_accessor :rack_app

      def start
        yield self
      end

      def request(req, body = nil)
        env = default_env
        env.merge!(path_env(req.path))
        env.merge!(method_env(req))
        env.merge!(header_env(req))
        env.merge!(io_env(req, body))
        response = build_response(@rack_app.call(env))
        yield response if block_given?
        return response
      end

      private

      def default_env
        {
          "SCRIPT_NAME" => "",
          "SERVER_NAME" => @address,
          "SERVER_PORT" => @port.to_s,   
          "rack.version" => [0,1],
          "rack.url_scheme" => "http",
          "rack.multithread" => true,
          "rack.multiprocess" => true,
          "rack.run_once" => false
        }
      end

      def method_env(request)
        {
          "REQUEST_METHOD" => request.method
        }
      end

      def io_env(request, body)
        raise(ArgumentError, "both request.body and body argument were provided") if (request.body && body)
        body ||= request.body || ""
        { 
          "rack.input" => StringIO.new(body.to_s),
          "rack.errors" => $stderr
        }
      end

      def path_env(path)
        uri = URI.parse(path)
        {
          "PATH_INFO" => uri.path,
          "QUERY_STRING" => (uri.query || ""),
        }
      end
{'fraction_non_alphanumeric': 0.12144344205412907, 'fraction_numerical': 0.0024288688410825814, 'mean_word_length': 1.6743970315398886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '5591865', 'n_tokens_mistral': 917, 'n_tokens_neox': 869, 'n_words': 178}