Skip to content

Instantly share code, notes, and snippets.

@anveo
Created December 17, 2012 19:00
Show Gist options
  • Save anveo/4320919 to your computer and use it in GitHub Desktop.
Save anveo/4320919 to your computer and use it in GitHub Desktop.
module Rack
class ServerNameHeader
attr_reader :app, :hostname
def initialize(app)
@app = app
@hostname = `hostname`.strip
end
def call(env)
status, headers, body = *app.call(env)
headers['X-Server-Name'] = hostname
[status, headers, body]
end
end
end
# config/environments/production.rb
require File.expand_path('../../../lib/rack/server_name_header', __FILE__)
My::Application.configure do
config.middleware.use Rack::ServerNameHeader
# all the other stuff
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment