Class: RackMonitor::RequestHostname
- Inherits:
-
Object
- Object
- RackMonitor::RequestHostname
- Defined in:
- lib/rack_monitor.rb
Overview
Simple middleware that adds the current host name and current git SHA to the response headers. This can help diagnose problems by letting you know what code is running from what machine.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ RequestHostname
constructor
Initializes the middlware.
Constructor Details
#initialize(app, options = {}) ⇒ RequestHostname
Initializes the middlware.
app - The next Rack app in the pipeline. options - Hash of options.
:host - String hostname.
:revision - String SHA that describes the version of code
this process is running.
Returns nothing.
67 68 69 70 71 |
# File 'lib/rack_monitor.rb', line 67 def initialize(app, = {}) @app = app @host = [:host] || `hostname -s`.chomp @sha = [:revision] || '<none>' end |
Instance Method Details
#call(env) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/rack_monitor.rb', line 73 def call(env) status, headers, body = @app.call(env) headers['X-Node'] = @host headers['X-Revision'] = @sha [status, headers, body] end |