def quick(req, res)
res['content-type'] = 'text/plain'
res['date'] = File.stat(@spec_dir).mtime
case req.request_uri.request_uri
when '/quick/index' then
res.body << @source_index.map { |name,_| name }.join("\n")
when '/quick/index.rz' then
index = @source_index.map { |name,_| name }.join("\n")
res.body << Zlib::Deflate.deflate(index)
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
selector = [$2, $3, $4].map { |s| s.inspect }.join ' '
platform = if $4 then
Gem::Platform.new $4.sub(/^-/, '')
else
Gem::Platform::RUBY
end
specs = specs.select { |s| s.platform == platform }
if specs.empty? then
res.status = 404
res.body = "No gems found matching #{selector}"
elsif specs.length > 1 then
res.status = 500
res.body = "Multiple gems found matching #{selector}"
elsif $1 then
res.body << Zlib::Deflate.deflate(Marshal.dump(specs.first))
else
res.body << Zlib::Deflate.deflate(specs.first.to_yaml)
end
else
res.status = 404
res.body = "#{req.request_uri} not found"
end
end