Rainbows! 5.2.1
[rainbows.git] / lib / rainbows / server_token.rb
blob09897d462771084b59a28d5efcefbbca1bef6c97
1 # -*- encoding: binary -*-
2 module Rainbows
4 # An optional middleware to proudly display your usage of \Rainbows! in
5 # the "Server:" response header.  This means you can help tell the world
6 # you're using \Rainbows! and spread fun and joy all over the Internet!
8 #    ------ in your config.ru ------
9 #    require 'rainbows/server_token'
10 #    require 'rack/lobster'
11 #    use Rainbows::ServerToken
12 #    run Rack::Lobster.new
14 # If you're nervous about the exact version of \Rainbows! you're running,
15 # then you can actually specify anything you want:
17 #    use Rainbows::ServerToken, "netcat 1.0"
20 class ServerToken < Struct.new(:app, :token)
22   def initialize(app, token = Const::RACK_DEFAULTS['SERVER_SOFTWARE'])
23     super
24   end
26   def call(env)
27     status, headers, body = app.call(env)
28     headers = Rack::Utils::HeaderHash.new(headers) unless Hash === headers
29     headers['Server'.freeze] = token
30     [ status, headers, body ]
31   end
32   # :startdoc:
33 end
34 end