Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 2d9252a227afdc99815cf3f628f5903a393f938b 0 parents
@mat mat authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 lib/rack/version_header.rb
31 lib/rack/version_header.rb
@@ -0,0 +1,31 @@
+module Rack
+
+ # Rack Version Header
+ # A Rack middleware for adding a version response header
+ # git show-ref --verify refs/heads/master --hash=8
+ class VersionHeader
+ F = ::File
+
+ def initialize(app, options={})
+ options[:header_name] ||= 'X-Version'
+ options[:version_file] ||= '.version'
+
+ @app = app
+ f = options[:version_file]
+ if F.exist?(f.to_s)
+ @rev = F.read(f.to_s)
+ else
+ @rev = 'unknown'
+ $stderr.puts("#{F.expand_path(f.to_s)} not found")
+ end
+ @header_name = options[:header_name]
+ end
+
+ def call(env)
+ status, headers, response = @app.call(env)
+ headers[@header_name] = @rev
+ [status, headers, response]
+ end
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.