1 # -*- encoding: binary -*-
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)
24 # Freeze constants as they're slightly faster when setting hashes
25 SERVER = "Server".freeze
27 def initialize(app, token = Const::RACK_DEFAULTS['SERVER_SOFTWARE'])
32 status, headers, body = app.call(env)
33 headers = Rack::Utils::HeaderHash.new(headers) unless Hash === headers
34 headers[SERVER] = token
35 [ status, headers, body ]