lib/roda/plugins/heartbeat.rb in roda-3.53.0 vs lib/roda/plugins/heartbeat.rb in roda-3.54.0
- old
+ new
@@ -12,10 +12,15 @@
#
# You can also specify a custom heartbeat path:
#
# plugin :heartbeat, path: '/status'
module Heartbeat
+ # :nocov:
+ HEADER_CLASS = (defined?(Rack::Headers) && Rack::Headers.is_a?(Class)) ? Rack::Headers : Hash
+ # :nocov:
+ private_constant :HEADER_CLASS
+
HEARTBEAT_RESPONSE = [200, {'Content-Type'=>'text/plain'}.freeze, ['OK'.freeze].freeze].freeze
# Set the heartbeat path to the given path.
def self.configure(app, opts=OPTS)
app.opts[:heartbeat_path] = (opts[:path] || app.opts[:heartbeat_path] || "/heartbeat").dup.freeze
@@ -26,10 +31,10 @@
# If the request is for a heartbeat path, return the heartbeat response.
def _roda_before_20__heartbeat
if env['PATH_INFO'] == opts[:heartbeat_path]
response = HEARTBEAT_RESPONSE.dup
- response[1] = Hash[response[1]]
+ response[1] = HEADER_CLASS[response[1]]
throw :halt, response
end
end
end
end