Class: Puma::App::Status
- Inherits:
-
Object
- Object
- Puma::App::Status
- Defined in:
- lib/puma/app/status.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Method Summary collapse
- #authenticate(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(server, cli) ⇒ Status
constructor
A new instance of Status.
Constructor Details
#initialize(server, cli) ⇒ Status
Returns a new instance of Status.
4 5 6 7 8 |
# File 'lib/puma/app/status.rb', line 4 def initialize(server, cli) @server = server @cli = cli @auth_token = nil end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
10 11 12 |
# File 'lib/puma/app/status.rb', line 10 def auth_token @auth_token end |
Instance Method Details
#authenticate(env) ⇒ Object
12 13 14 15 |
# File 'lib/puma/app/status.rb', line 12 def authenticate(env) return true unless @auth_token env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}") end |
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puma/app/status.rb', line 17 def call(env) unless authenticate(env) return [403, {}, ["Invalid auth token"]] end case env['PATH_INFO'] when "/stop" @server.stop return [200, {}, ['{ "status": "ok" }']] when "/halt" @server.halt return [200, {}, ['{ "status": "ok" }']] when "/restart" if @cli and @cli.restart_on_stop! @server.stop return [200, {}, ['{ "status": "ok" }']] else return [200, {}, ['{ "status": "not configured" }']] end when "/stats" b = @server.backlog r = @server.running return [200, {}, ["{ \"backlog\": #{b}, \"running\": #{r} }"]] end [404, {}, ["Unsupported action"]] end |