Class: Rainbows::ServerToken

Inherits:
Struct
  • Object
show all
Defined in:
lib/rainbows/server_token.rb

Overview

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"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, token = Const::RACK_DEFAULTS['SERVER_SOFTWARE']) ⇒ ServerToken

Returns a new instance of ServerToken.



22
23
24
# File 'lib/rainbows/server_token.rb', line 22

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

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



20
21
22
# File 'lib/rainbows/server_token.rb', line 20

def app
  @app
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



20
21
22
# File 'lib/rainbows/server_token.rb', line 20

def token
  @token
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
# File 'lib/rainbows/server_token.rb', line 26

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