Sha256: 4b60b543b69c55198788382cba64ac9e4904030b016ebe77a6f5cdc3f11f3e92

Contents?: true

Size: 1.14 KB

Versions: 14

Compression:

Stored size: 1.14 KB

Contents

module Puma
  module App
    class Status
      def initialize(server, cli)
        @server = server
        @cli = cli
        @auth_token = nil
      end

      attr_accessor :auth_token

      def authenticate(env)
        return true unless @auth_token
        env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
      end

      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
puma-1.1.1-java lib/puma/app/status.rb
puma-1.1.1 lib/puma/app/status.rb
puma-1.1.0-java lib/puma/app/status.rb
puma-1.1.0 lib/puma/app/status.rb
puma-1.0.0-java lib/puma/app/status.rb
puma-1.0.0 lib/puma/app/status.rb
puma-0.9.5-java lib/puma/app/status.rb
puma-0.9.5 lib/puma/app/status.rb
puma-0.9.4-java lib/puma/app/status.rb
puma-0.9.4 lib/puma/app/status.rb
puma-0.9.3-java lib/puma/app/status.rb
puma-0.9.3 lib/puma/app/status.rb
puma-0.9.2-java lib/puma/app/status.rb
puma-0.9.2 lib/puma/app/status.rb