Class: Jets::Server::TimingMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/server/timing_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TimingMiddleware

Returns a new instance of TimingMiddleware.



3
4
5
# File 'lib/jets/server/timing_middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/jets/server/timing_middleware.rb', line 7

def call(env)
  before = Time.now.to_i
  status, headers, body = @app.call(env)
  after = Time.now.to_i
  log_message = "App took #{after - before} seconds.\n"
  headers["Timing"] = "App took #{after - before} seconds.\n"
  [status, headers, body]
end