Skip to content

Instantly share code, notes, and snippets.

@ryansmith3136
Created October 30, 2012 18:59
Show Gist options
  • Select an option

  • Save ryansmith3136/3982276 to your computer and use it in GitHub Desktop.

Select an option

Save ryansmith3136/3982276 to your computer and use it in GitHub Desktop.
Middleware to respond to HTTP HEAD /
# Add this file to /lib/health.rb
# Require in config/application.rb
# require File.join(File.dirname(__FILE__), '../lib/health.rb')
# Load in config/application.rb
# config.middleware.use Heroku::HttpHealth
# Be sure to put this middleware at the front of all other middlewares. Don't want authentication on this guy.
class Heroku::HttpHealth
def initialize(app)
@app = app
end
def call(env)
if env["PATH_INFO"] =~ /\A\/?\z/ && env["REQUEST_METHOD"] == "HEAD"
[200, {"Content-Type" => "text/plain"}, ["OK"]]
else
@app.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment