Sha256: cffe6e2429260e79e00e13826c568e53f93fb908a8ae02b719341be456c5cec1

Contents?: true

Size: 1.43 KB

Versions: 49

Compression:

Stored size: 1.43 KB

Contents

module Puma
  module App
    class Status
      def initialize(cli)
        @cli = cli
        @auth_token = nil
      end
      OK_STATUS = '{ "status": "ok" }'.freeze

      attr_accessor :auth_token

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

      def rack_response(status, body, content_type='application/json')
        headers = {
          'Content-Type' => content_type,
          'Content-Length' => body.bytesize.to_s
        }

        [status, headers, [body]]
      end

      def call(env)
        unless authenticate(env)
          return rack_response(403, 'Invalid auth token', 'text/plain')
        end

        case env['PATH_INFO']
        when /\/stop$/
          @cli.stop
          return rack_response(200, OK_STATUS)

        when /\/halt$/
          @cli.halt
          return rack_response(200, OK_STATUS)

        when /\/restart$/
          @cli.restart
          return rack_response(200, OK_STATUS)

        when /\/phased-restart$/
          if !@cli.phased_restart
            return rack_response(404, '{ "error": "phased restart not available" }')
          else
            return rack_response(200, OK_STATUS)
          end

        when /\/stats$/
          return rack_response(200, @cli.stats)
        else
          rack_response 404, "Unsupported action", 'text/plain'
        end
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 4 rubygems

Version Path
puma-2.10.2-java lib/puma/app/status.rb
puma-2.10.2 lib/puma/app/status.rb
puma-2.10.1-java lib/puma/app/status.rb
puma-2.10.1 lib/puma/app/status.rb
puma-2.10.0-java lib/puma/app/status.rb
puma-2.10.0 lib/puma/app/status.rb
wendell-puma-2.9.2 lib/puma/app/status.rb
rsense-server-0.5.18 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb
puma-2.9.2-java lib/puma/app/status.rb
puma-2.9.2 lib/puma/app/status.rb
puma-2.9.1-java lib/puma/app/status.rb
puma-2.9.1 lib/puma/app/status.rb
puma-2.9.0-java lib/puma/app/status.rb
puma-2.9.0 lib/puma/app/status.rb
rsense-server-0.5.17 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb
rsense-server-0.5.16 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb
rsense-server-0.5.15 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb
rsense-server-0.5.14 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb
rsense-server-0.5.13 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb
rsense-server-0.5.12 vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb