diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-06-10 18:22:25 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-06-10 18:28:21 -0700 |
commit | cf47d3e51d7b0aecdda8b0f27631161977900a47 (patch) | |
tree | a549cbb1b90e4e5ba2bda39345598156e756e9aa /lib/rainbows/server_token.rb | |
parent | b73218100032ead24360d33361fefa914074f30a (diff) | |
download | rainbows-cf47d3e51d7b0aecdda8b0f27631161977900a47.tar.gz |
Some folks can now show off their Rainbows! installation
Diffstat (limited to 'lib/rainbows/server_token.rb')
-rw-r--r-- | lib/rainbows/server_token.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/rainbows/server_token.rb b/lib/rainbows/server_token.rb new file mode 100644 index 0000000..4098ca7 --- /dev/null +++ b/lib/rainbows/server_token.rb @@ -0,0 +1,39 @@ +# -*- 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) + + # :stopdoc: + # + # Freeze constants as they're slightly faster when setting hashes + SERVER = "Server".freeze + + 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) + headers[SERVER] = token + [ status, headers, body ] + end + # :startdoc: +end +end |