aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/server.rb')
-rw-r--r--lib/rubygems/server.rb59
1 files changed, 19 insertions, 40 deletions
diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb
index 3b966f269b..76cb22f252 100644
--- a/lib/rubygems/server.rb
+++ b/lib/rubygems/server.rb
@@ -1,5 +1,10 @@
+######################################################################
+# This file is imported from the rubygems project.
+# DO NOT make modifications in this repo. They _will_ be reverted!
+# File a patch instead and assign it to Ryan Davis or Eric Hodel.
+######################################################################
+
require 'webrick'
-require 'yaml'
require 'zlib'
require 'erb'
@@ -21,7 +26,6 @@ require 'rubygems/doc_manager'
# * legacy indexes:
# * "/Marshal.#{Gem.marshal_version}" - Full SourceIndex dump of metadata
# for installed gems
-# * "/yaml" - YAML dump of metadata for installed gems - deprecated
#
# == Usage
#
@@ -429,18 +433,19 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
def self.run(options)
new(options[:gemdir], options[:port], options[:daemon],
- options[:addresses]).run
+ options[:launch], options[:addresses]).run
end
##
# Only the first directory in gem_dirs is used for serving gems
- def initialize(gem_dirs, port, daemon, addresses = nil)
+ def initialize(gem_dirs, port, daemon, launch = nil, addresses = nil)
Socket.do_not_reverse_lookup = true
@gem_dirs = Array gem_dirs
@port = port
@daemon = daemon
+ @launch = launch
@addresses = addresses
logger = WEBrick::Log.new nil, WEBrick::BasicLog::FATAL
@server = WEBrick::HTTPServer.new :DoNotListen => true, :Logger => logger
@@ -553,19 +558,6 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
add_date res
case req.request_uri.path
- when '/quick/index' then
- res.body << @source_index.map { |name,| name }.sort.join("\n")
- when '/quick/index.rz' then
- index = @source_index.map { |name,| name }.sort.join("\n")
- res['content-type'] = 'application/x-deflate'
- res.body << Gem.deflate(index)
- when '/quick/latest_index' then
- index = @source_index.latest_specs.map { |spec| spec.full_name }
- res.body << index.sort.join("\n")
- when '/quick/latest_index.rz' then
- index = @source_index.latest_specs.map { |spec| spec.full_name }
- res['content-type'] = 'application/x-deflate'
- res.body << Gem.deflate(index.sort.join("\n"))
when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)-([0-9.]+)(-.*?)?\.gemspec\.rz$| then
dep = Gem::Dependency.new $2, $3
specs = @source_index.search dep
@@ -590,9 +582,6 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
elsif marshal_format then
res['content-type'] = 'application/x-deflate'
res.body << Gem.deflate(Marshal.dump(specs.first))
- else # deprecated YAML format
- res['content-type'] = 'application/x-deflate'
- res.body << Gem.deflate(specs.first.to_yaml)
end
else
raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
@@ -675,6 +664,9 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
values = { "gem_count" => specs.size.to_s, "specs" => specs,
"total_file_count" => total_file_count.to_s }
+ # suppress 1.9.3dev warning about unused variable
+ values = values
+
result = template.result binding
res.body = result
end
@@ -768,9 +760,6 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
WEBrick::Daemon.start if @daemon
- @server.mount_proc "/yaml", method(:yaml)
- @server.mount_proc "/yaml.Z", method(:yaml)
-
@server.mount_proc "/Marshal.#{Gem.marshal_version}", method(:Marshal)
@server.mount_proc "/Marshal.#{Gem.marshal_version}.Z", method(:Marshal)
@@ -803,6 +792,8 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
trap("INT") { @server.shutdown; exit! }
trap("TERM") { @server.shutdown; exit! }
+ launch if @launch
+
@server.start
end
@@ -833,26 +824,14 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
end
end
- def yaml(req, res)
- @source_index.refresh!
+ def launch
+ listeners = @server.listeners.map{|l| l.addr[2] }
- add_date res
+ host = listeners.any?{|l| l == '0.0.0.0'} ? 'localhost' : listeners.first
- index = @source_index.to_yaml
+ say "Launching browser to http://#{host}:#{@port}"
- if req.path =~ /Z$/ then
- res['content-type'] = 'application/x-deflate'
- index = Gem.deflate index
- else
- res['content-type'] = 'text/plain'
- end
-
- if req.request_method == 'HEAD' then
- res['content-length'] = index.length
- return
- end
-
- res.body << index
+ system("#{@launch} http://#{host}:#{@port}")
end
end