Sha256: 426adf7121b8e68a064801ce722665fdb95f152729fe90743d3f943037ed051f

Contents?: true

Size: 763 Bytes

Versions: 1

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

require 'rack/ok/version'

module Rack
  class Ok
    DEFAULT_REQUEST_PATH = '/health'

    DEFAULT_RESPONSE_BODY = 'OK'

    # @param [#call] app
    # @param [String] body
    # @param [String] path
    def initialize(
      app,
      body: DEFAULT_RESPONSE_BODY,
      path: DEFAULT_REQUEST_PATH
    )
      @app = app
      @body = body
      @path = path
    end

    # @param [Hash] env Rack env.
    # @return [Array] Rack response.
    def call(env)
      if env['PATH_INFO'] == @path
        [
          '200',
          {
            'Content-Length' => @body.bytesize.to_s,
            'Content-Type' => 'text/plain'
          },
          [@body]
        ]
      else
        @app.call(env)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-ok-0.1.0 lib/rack/ok.rb