Skip to content
Browse files

Add geminabox version to HTTP responses

It's useful for us to know, which version of which software
is serving gems. This patch adds an `"X-Powered-By"` response
header with the value of `"geminabox VERSION"`, e.g. `"geminabox 0.6.0"`.

Example:

    geminabox$ bundle exec rackup
    $ curl -I localhost:9292
    HTTP/1.1 200 OK
    ...
    X-Powered-By: geminabox 0.6.0
  • Loading branch information...
1 parent 6ed6af0 commit 00f6fce72f2b651c0439dbcb8497e9babf536390 @exviva exviva committed with tomlea Mar 9, 2012
Showing with 34 additions and 2 deletions.
  1. +6 −1 Rakefile
  2. +5 −1 geminabox.gemspec
  3. +5 −0 lib/geminabox.rb
  4. +18 −0 test/requests/x_powered_by_test.rb
View
7 Rakefile
@@ -25,6 +25,11 @@ task "test:smoke" do
require "smoke_test"
end
+Rake::TestTask.new("test:requests") do |t|
+ t.libs << "test" << "lib"
+ t.pattern = "test/requests/**/*_test.rb"
+end
+
task :st => "test:smoke"
-task :test => "test:integration"
+task :test => ["test:requests", "test:integration"]
task :default => :test
View
6 geminabox.gemspec
@@ -1,6 +1,9 @@
+$:.push File.expand_path('../lib', __FILE__)
+require 'geminabox'
+
Gem::Specification.new do |s|
s.name = 'geminabox'
- s.version = '0.6.0'
+ s.version = Geminabox::VERSION
s.summary = 'Really simple rubygem hosting'
s.description = 'A sinatra based gem hosting app, with client side gem push style functionality.'
s.author = 'Tom Lea'
@@ -18,5 +21,6 @@ Gem::Specification.new do |s|
s.add_dependency('builder')
s.add_dependency('httpclient')
s.add_development_dependency('rake')
+ s.add_development_dependency('rack-test')
s.add_development_dependency('minitest')
end
View
5 lib/geminabox.rb
@@ -7,6 +7,7 @@
require 'hostess'
class Geminabox < Sinatra::Base
+ VERSION = '0.6.0'
enable :static, :methodoverride
set :public_folder, File.join(File.dirname(__FILE__), *%w[.. public])
@@ -31,6 +32,10 @@ def fixup_bundler_rubygems!
autoload :GemVersionCollection, "geminabox/gem_version_collection"
+ before do
+ headers 'X-Powered-By' => "geminabox #{VERSION}"
+ end
+
get '/' do
@gems = load_gems
@index_gems = index_gems(@gems)
View
18 test/requests/x_powered_by_test.rb
@@ -0,0 +1,18 @@
+require 'test_helper'
+require 'minitest/unit'
+require 'rack/test'
+
+class XPoweredByTest < MiniTest::Unit::TestCase
+ include Rack::Test::Methods
+
+ def app
+ Geminabox
+ end
+
+ %w[ / /gems ].each do |path|
+ define_method "test: adds X-Powered-By when requesting '#{path}'" do
+ get path
+ assert_equal "geminabox #{Geminabox::VERSION}", last_response.headers['X-Powered-By']
+ end
+ end
+end

0 comments on commit 00f6fce

Please sign in to comment.
Something went wrong with that request. Please try again.