summaryrefslogtreecommitdiff
path: root/lib/rainbows/server_token.rb
blob: 09897d462771084b59a28d5efcefbbca1bef6c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- encoding: binary -*-
module Rainbows

# An optional middleware to proudly display your usage of \Rainbows! in
# the "Server:" response header.  This means you can help tell the world
# you're using \Rainbows! and spread fun and joy all over the Internet!
#
#    ------ in your config.ru ------
#    require 'rainbows/server_token'
#    require 'rack/lobster'
#    use Rainbows::ServerToken
#    run Rack::Lobster.new
#
# If you're nervous about the exact version of \Rainbows! you're running,
# then you can actually specify anything you want:
#
#    use Rainbows::ServerToken, "netcat 1.0"
#

class ServerToken < Struct.new(:app, :token)

  def initialize(app, token = Const::RACK_DEFAULTS['SERVER_SOFTWARE'])
    super
  end

  def call(env)
    status, headers, body = app.call(env)
    headers = Rack::Utils::HeaderHash.new(headers) unless Hash === headers
    headers['Server'.freeze] = token
    [ status, headers, body ]
  end
  # :startdoc:
end
end