Class: Puma::App::Status
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/puma/app/status.rb |
Overview
Check out #call‘s source code to see what actions this web application can respond to.
Constant Summary
-
OK_STATUS =
# File 'lib/puma/app/status.rb', line 8'{ "status": "ok" }'.freeze
Class Method Summary
- .new(cli, token = nil) ⇒ Status constructor
Instance Method Summary
Constructor Details
.new(cli, token = nil) ⇒ Status
# File 'lib/puma/app/status.rb', line 10
def initialize(cli, token = nil) @cli = cli @auth_token = token end
Instance Method Details
#authenticate(env) (private)
[ GitHub ]# File 'lib/puma/app/status.rb', line 67
def authenticate(env) return true unless @auth_token env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}") end
#call(env)
[ GitHub ]# File 'lib/puma/app/status.rb', line 15
def call(env) unless authenticate(env) return rack_response(403, 'Invalid auth token', 'text/plain') end if env['PATH_INFO'] =~ /\/(gc-stats|stats|thread-backtraces)$/ require 'json' end case env['PATH_INFO'] when /\/stop$/ @cli.stop rack_response(200, OK_STATUS) when /\/halt$/ @cli.halt rack_response(200, OK_STATUS) when /\/restart$/ @cli.restart rack_response(200, OK_STATUS) when /\/phased-restart$/ if !@cli.phased_restart rack_response(404, '{ "error": "phased restart not available" }') else rack_response(200, OK_STATUS) end when /\/reload-worker-directory$/ if !@cli.send(:reload_worker_directory) rack_response(404, '{ "error": "reload_worker_directory not available" }') else rack_response(200, OK_STATUS) end when /\/gc$/ GC.start rack_response(200, OK_STATUS) when /\/gc-stats$/ rack_response(200, GC.stat.to_json) when /\/stats$/ rack_response(200, @cli.stats) else rack_response 404, "Unsupported action", 'text/plain' end end
#rack_response(status, body, content_type = 'application/json') (private)
[ GitHub ]# File 'lib/puma/app/status.rb', line 72
def rack_response(status, body, content_type='application/json') headers = { 'Content-Type' => content_type, 'Content-Length' => body.bytesize.to_s } [status, headers, [body]] end