<commit_before>require 'rack'

module Yarrow
  ##
  # Little web server for browsing local files.
  class Server
    include Configurable

    def initialize
      if config.server.nil?
        raise ConfigurationError.new('Missing server entry')
      end
    end

    ##
    # Rack Middleware for detecting and serving an 'index.html' file
    # instead of a directory index.
    #
    # TODO: Add configurable mapping and media types for README files as an alternative
    class DirectoryIndex
      def initialize(app, options={})
        @app = app
        @root = options[:root]
        @index_file = options[:index]
      end

      def call(env)
        index_path = File.join(@root, Rack::Request.new(env).path.split('/'), @index_file)
        if File.exists?(index_path)
          return [200, {"Content-Type" => "text/html"}, [File.read(index_path)]]
        else
          @app.call(env)
        end
      end
    end

    ##
    # Sets a default content type for files without an extension. Everything else
    # falls through according to the implementations of Rack::File and Rack::Mime.
    #
    class DefaultContentType
      def initialize(app, content_type)
        @app = app
        @content_type = content_type
      end

      def call(env)
        request = Rack::Request.new(env)

        if File.basename(File.extname(request.path)).empty?

        end

        @app.call(env)
      end
    end

    ##
    # Builds a Rack application to serve files in the output directory.
    #
    # If no output directory is specified, defaults to the current working
    # directory.
    #
    # @return [Yarrow::Server::StaticFiles]
    def app
      root = docroot
      index = default_index
      middleware_stack = middleware_map
      auto_index = auto_index?
      mime_type = default_type

      Rack::Builder.new do
        middleware_stack.each do |middleware|
          use middleware
        end

        #use DefaultContentType, 'text/html'
        use DirectoryIndex, root: root, index: index

        app_args = [root, {}].tap { |args| args.push(mime_type) if mime_type }
        static_app = Rack::File.new(*app_args)
<commit_msg>Remove unused content-type middleware<commit_after>require 'rack'

module Yarrow
  ##
  # Little web server for browsing local files.
  class Server
    include Configurable

    def initialize
      if config.server.nil?
        raise ConfigurationError.new('Missing server entry')
      end
    end

    ##
    # Rack Middleware for detecting and serving an 'index.html' file
    # instead of a directory index.
    #
    # TODO: Add configurable mapping and media types for README files as an alternative
    class DirectoryIndex
      def initialize(app, options={})
        @app = app
        @root = options[:root]
        @index_file = options[:index]
      end

      def call(env)
        index_path = File.join(@root, Rack::Request.new(env).path.split('/'), @index_file)
        if File.exists?(index_path)
          return [200, {"Content-Type" => "text/html"}, [File.read(index_path)]]
        else
          @app.call(env)
        end
      end
    end

    ##
    # Builds a Rack application to serve files in the output directory.
    #
    # If no output directory is specified, defaults to the current working
    # directory.
    #
    # @return [Yarrow::Server::StaticFiles]
    def app
      root = docroot
      index = default_index
      middleware_stack = middleware_map
      auto_index = auto_index?
      mime_type = default_type

      Rack::Builder.new do
        middleware_stack.each do |middleware|
          use middleware
        end

        use DirectoryIndex, root: root, index: index

        app_args = [root, {}].tap { |args| args.push(mime_type) if mime_type }
        static_app = Rack::File.new(*app_args)

{'fraction_non_alphanumeric': 0.090527420624508, 'fraction_numerical': 0.001574389923904487, 'mean_word_length': 2.3292576419213975, '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': '617764', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1081, 'n_words': 332}