Sha256: 7bbeae84fe66b80618b558614d65159f383e9383f8b2beeae422ef960f876b60

Contents?: true

Size: 686 Bytes

Versions: 30

Compression:

Stored size: 686 Bytes

Contents

class Jets::Server
  class TimingMiddleware
    FORMAT_STRING = "%0.6f" # :nodoc:
    HEADER_NAME = "X-Runtime" # :nodoc:

    def initialize(app)
      @app = app
    end

    def call(env)
      start_time = clock_time
      status, headers, body = @app.call(env)
      request_time = clock_time - start_time

      unless headers.has_key?(HEADER_NAME)
        headers[HEADER_NAME] = FORMAT_STRING % request_time
      end

      [status, headers, body]
    end

    private
    if defined?(Process::CLOCK_MONOTONIC)
      def clock_time
        Process.clock_gettime(Process::CLOCK_MONOTONIC)
      end
    else
      def clock_time
        Time.now.to_f
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
jets-1.0.18 lib/jets/server/timing_middleware.rb
jets-1.0.17 lib/jets/server/timing_middleware.rb
jets-1.0.16 lib/jets/server/timing_middleware.rb
jets-1.0.15 lib/jets/server/timing_middleware.rb
jets-1.0.13 lib/jets/server/timing_middleware.rb
jets-1.0.12 lib/jets/server/timing_middleware.rb
jets-1.0.11 lib/jets/server/timing_middleware.rb
jets-1.0.10 lib/jets/server/timing_middleware.rb
jets-1.0.9 lib/jets/server/timing_middleware.rb
jets-1.0.8 lib/jets/server/timing_middleware.rb
jets-1.0.7 lib/jets/server/timing_middleware.rb
jets-1.0.6 lib/jets/server/timing_middleware.rb
jets-1.0.5 lib/jets/server/timing_middleware.rb
jets-1.0.4 lib/jets/server/timing_middleware.rb
jets-1.0.3 lib/jets/server/timing_middleware.rb
jets-1.0.2 lib/jets/server/timing_middleware.rb
jets-1.0.1 lib/jets/server/timing_middleware.rb
jets-1.0.0 lib/jets/server/timing_middleware.rb
jets-0.10.4 lib/jets/server/timing_middleware.rb
jets-0.10.3 lib/jets/server/timing_middleware.rb