<commit_before>require 'rack/request'

module Hoth
  module Providers
    class RackProvider

      def initialize(app)
        @app = app
      end

      def call(env)
        Hoth::Logger.debug "env: #{env.inspect}"
        if env["PATH_INFO"] =~ /^\/execute/
          begin
            req = Rack::Request.new(env)
            Hoth::Logger.debug "req: #{req.inspect}"

            service_name   = req.params["name"]
            service_params = req.params["params"]

            raise EmptyServiceNameError.new("You must provide a service name!") if service_name.nil?

            responsible_service = ServiceRegistry.locate_service(service_name)

            raise ServiceNotFoundException.new("The requested service '#{service_name}' was not found!") if responsible_service.nil?

            # check if we have called ourself
            raise RecursiveServiceCallException.new("Service caller and callee have the same Client-UUID!") if req.params["caller_uuid"] == Hoth.client_uuid

            decoded_params = responsible_service.transport.encoder.decode(service_params)
            result = Hoth::Services.send(service_name, *decoded_params)

            encoded_result = responsible_service.transport.encoder.encode({"result" => result})
<commit_msg>Provide default RackApplication for RackProvider<commit_after>require 'rack/request'

module Hoth
  module Providers
    class RackProvider

      def initialize(app=nil)
        @app = app || lambda {|env| [404, {'Content-Type' => "text/plain"}, ["Nothing here!"]]}
      end

      def call(env)
        Hoth::Logger.debug "env: #{env.inspect}"
        if env["PATH_INFO"] =~ /^\/execute/
          begin
            req = Rack::Request.new(env)
            Hoth::Logger.debug "req: #{req.inspect}"

            service_name   = req.params["name"]
            service_params = req.params["params"]

            raise EmptyServiceNameError.new("You must provide a service name!") if service_name.nil?

            responsible_service = ServiceRegistry.locate_service(service_name)

            raise ServiceNotFoundException.new("The requested service '#{service_name}' was not found!") if responsible_service.nil?

            # check if we have called ourself
            raise RecursiveServiceCallException.new("Service caller and callee have the same Client-UUID!") if req.params["caller_uuid"] == Hoth.client_uuid

            decoded_params = responsible_service.transport.encoder.decode(service_params)
            result = Hoth::Services.send(service_name, *decoded_params)

            encoded_result = responsible_service.transport.encoder.encode({"result" => result})

{'fraction_non_alphanumeric': 0.10665658093797277, 'fraction_numerical': 0.0011346444780635401, 'mean_word_length': 2.889705882352941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6521810', 'n_tokens_mistral': 730, 'n_tokens_neox': 707, 'n_words': 167}