Skip to content

Instantly share code, notes, and snippets.

@darashi
Created May 20, 2009 11:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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