Repository: puma/puma
File: lib/puma/app/status.rb (Ruby)

Code before:
    class Status
      OK_STATUS = '{ "status": "ok" }'.freeze
      READ_ONLY_COMMANDS = %w[gc-stats stats].freeze

      # @param launcher [::Puma::Launcher]
      # @param token [String, nil] the token used for authentication
      # @param data_only [Boolean] if true, restrict to read-only data commands
      #
      def initialize(launcher, token = nil, data_only = false)
        @launcher = launcher
        @auth_token = token
        @enabled_commands = READ_ONLY_COMMANDS if data_only
      end

      # most commands call methods in `::Puma::Launcher` based on command in
      # `env['PATH_INFO']`
      def call(env)
        unless authenticate(env)
          return rack_response(403, 'Invalid auth token', 'text/plain')
        end

        # resp_type is processed by following case statement, return
        # is a number (status) or a string used as the body of a 200 response
        command = env['PATH_INFO'][/\/([^\/]+)$/, 1]
        if @enabled_commands && !@enabled_commands.include?(command)
          return rack_response(404, "Command disabled", 'text/plain')
        end

        resp_type =
          case command
          when 'stop'
            @launcher.stop ; 200

          when 'halt'
            @launcher.halt ; 200

          when 'restart'
            @launcher.restart ; 200

          when 'phased-restart'
            @launcher.phased_restart ? 200 : 404

          when 'refork'
            @launcher.refork ? 200 : 404

          when 'reload-worker-directory'
            @launcher.send(:reload_worker_directory) ? 200 : 404

          when 'gc'
            GC.start ; 200


Review comment (suggestion):
If someone hits this with a non-existant command, it's not technically "disabled" but it is unavailable. 

```suggestion
          return rack_response(404, "Command #{command.inspect} unavailable", 'text/plain')
```

Also I like showing people what the code is seeing which might help them realize there's a typo or something else is off like random accidental whitespace.

Code after:
    class Status
      OK_STATUS = '{ "status": "ok" }'.freeze
      READ_ONLY_COMMANDS = %w[gc-stats stats].freeze

      # @param launcher [::Puma::Launcher]
      # @param token [String, nil] the token used for authentication
      # @param data_only [Boolean] if true, restrict to read-only data commands
      #
      def initialize(launcher, token: nil, data_only: false)
        @launcher = launcher
        @auth_token = token
        @enabled_commands = READ_ONLY_COMMANDS if data_only
      end

      # most commands call methods in `::Puma::Launcher` based on command in
      # `env['PATH_INFO']`
      def call(env)
        unless authenticate(env)
          return rack_response(403, 'Invalid auth token', 'text/plain')
        end

        # resp_type is processed by following case statement, return
        # is a number (status) or a string used as the body of a 200 response
        command = env['PATH_INFO'][/\/([^\/]+)$/, 1]
        if @enabled_commands && !@enabled_commands.include?(command)
          return rack_response(404, "Command #{command.inspect} unavailable", 'text/plain')
        end

        resp_type =
          case command
          when 'stop'
            @launcher.stop ; 200

          when 'halt'
            @launcher.halt ; 200

          when 'restart'
            @launcher.restart ; 200

          when 'phased-restart'
            @launcher.phased_restart ? 200 : 404

          when 'refork'
            @launcher.refork ? 200 : 404

          when 'reload-worker-directory'
            @launcher.send(:reload_worker_directory) ? 200 : 404

          when 'gc'
            GC.start ; 200