Skip to content

Instantly share code, notes, and snippets.

@darashi
Created May 20, 2009 11:44
Show Gist options
  • Save darashi/114761 to your computer and use it in GitHub Desktop.
Save darashi/114761 to your computer and use it in GitHub Desktop.
add X-Git-Commit header to Rack application
# Rack middleware to insert git commit id into http response header
# For Rails, put this script under RAILS_ROOT/config/initializers
module Rack
class GitCommitHeader
def initialize(app)
@app = app
c = `git rev-parse HEAD`.chomp
@commit = (c =~ /^[0-9a-f]{40}$/) ? c : nil
end
def call(env)
status, headers, body = @app.call(env)
headers['X-Git-Commit'] = @commit if @commit
[status, headers, body]
end
end
end
ActionController::Dispatcher.middleware.use Rack::GitCommitHeader rescue nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment