run (Gem::Server)

    # File lib/rubygems/server.rb, line 404
      def run
        @server.listen nil, @port

        say "Starting gem server on http://localhost:#{@port}/"

        WEBrick::Daemon.start if @daemon

        @server.mount_proc("/yaml") do |req, res|
          res['content-type'] = 'text/plain'
          res['date'] = File.stat(@spec_dir).mtime
          if req.request_method == 'HEAD' then
            res['content-length'] = @source_index.to_yaml.length
          else
            res.body << @source_index.to_yaml
          end
        end

        @server.mount_proc("/Marshal") do |req, res|
          res['content-type'] = 'text/plain'
          res['date'] = File.stat(@spec_dir).mtime
          if req.request_method == 'HEAD' then
            res['content-length'] = Marshal.dump(@source_index).length
          else
            res.body << Marshal.dump(@source_index)
          end
        end

        @server.mount_proc("/quick/", &method(:quick))

        @server.mount_proc("/gem-server-rdoc-style.css") do |req, res|
          res['content-type'] = 'text/css'
          res['date'] = File.stat(@spec_dir).mtime
          res.body << RDOC_CSS
        end

        @server.mount_proc("/") do |req, res|
          specs = []
          total_file_count = 0

          @source_index.each do |path, spec|
            total_file_count += spec.files.size
            deps = spec.dependencies.collect { |dep|
              { "name"    => dep.name,
                "version" => dep.version_requirements.to_s, }
            }
            deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] }
            deps.last["is_last"] = true unless deps.empty?

            # executables
            executables = spec.executables.sort.collect { |exec| {"executable" => exec} }
            executables = nil if executables.empty?
            executables.last["is_last"] = true if executables

            specs << {
              "authors"        => spec.authors.sort.join(", "),
              "date"           => spec.date.to_s,
              "dependencies"   => deps,
              "doc_path"       => ('/doc_root/' + spec.full_name + '/rdoc/index.html'),
              "executables"    => executables,
              "only_one_executable" => (executables && executables.size==1),
              "full_name"      => spec.full_name,
              "has_deps"       => !deps.empty?,
              "homepage"       => spec.homepage,
              "name"           => spec.name,
              "rdoc_installed" => Gem::DocManager.new(spec).rdoc_installed?,
              "summary"        => spec.summary,
              "version"        => spec.version.to_s,
            }
          end

          specs << {
            "authors" => "Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel and others",
            "dependencies" => [],
            "doc_path" => "/doc_root/rubygems-#{Gem::RubyGemsVersion}/rdoc/index.html",
            "executables" => [{"executable" => 'gem', "is_last" => true}],
            "only_one_executable" => true,
            "full_name" => "rubygems-#{Gem::RubyGemsVersion}",
            "has_deps" => false,
            "homepage" => "http://rubygems.org/",
            "name" => 'rubygems',
            "rdoc_installed" => true,
            "summary" => "RubyGems itself",
            "version" => Gem::RubyGemsVersion,
          }

          specs = specs.sort_by { |spec| [spec["name"].downcase, spec["version"]] }
          specs.last["is_last"] = true

          # tag all specs with first_name_entry
          last_spec = nil
          specs.each do |spec|
            is_first = last_spec.nil? || (last_spec["name"].downcase != spec["name"].downcase)
            spec["first_name_entry"] = is_first
            last_spec = spec
          end

          # create page from template
          template = TemplatePage.new(DOC_TEMPLATE)
          res['content-type'] = 'text/html'
          template.write_html_on res.body,
                                 "gem_count" => specs.size.to_s, "specs" => specs,
                                 "total_file_count" => total_file_count.to_s
        end

        paths = { "/gems" => "/cache/", "/doc_root" => "/doc/" }
        paths.each do |mount_point, mount_dir|
          @server.mount(mount_point, WEBrick::HTTPServlet::FileHandler,
                  File.join(@gemdir, mount_dir), true)
        end

        trap("INT") { @server.shutdown; exit! }
        trap("TERM") { @server.shutdown; exit! }

        @server.start
      end