<commit_before>module Tassadar
  module Server
    class Whitelist
      def initialize(app, addresses)
        @app = app
        @whitelist = addresses
      end

      def call(env)
        if white_listed?(env)
          @app.call(env)
        else
          [ 403,
            { 'Content-Type' => 'text/plain; charset=utf-8' },
            Array( "IP #{remote_ip(env)} is not whitelisted" )
          ]
        end
      end

      def remote_ip(env)
        if env.include? 'HTTP_X_FORWARDED_FOR'
          env['HTTP_X_FORWARDED_FOR']
        else
          env['REMOTE_ADDR']
        end
      end
      
      def white_listed?(env)
        @whitelist.include? remote_ip(env)
      end
    end
  end
end<commit_msg>Delegate to rack for ip resolution, more possible cases there than I anticipated<commit_after>module Tassadar
  module Server
    class Whitelist
      def initialize(app, addresses)
        @app = app
        @whitelist = addresses
      end

      def call(env)
        if white_listed?(env)
          @app.call(env)
        else
          [ 403,
            { 'Content-Type' => 'text/plain; charset=utf-8' },
            Array( "IP #{remote_ip(env)} is not whitelisted" )
          ]
        end
      end

      def remote_ip(env)
        Rack::Request.new(env).ip
      end
      
      def white_listed?(env)
        @whitelist.include? remote_ip(env)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09161931818181818, 'fraction_numerical': 0.005681818181818182, 'mean_word_length': 1.668560606060606, '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': '1762769', 'n_tokens_mistral': 449, 'n_tokens_neox': 436, 'n_words': 105}