跳至内容 跳至搜索
方法
C
N

类公共方法

new(app)

# File actionpack/lib/action_dispatch/middleware/server_timing.rb, line 52
def initialize(app)
  @app = app
  @subscriber = Subscriber.instance
  @subscriber.ensure_subscribed
end

实例公共方法

call(env)

# File actionpack/lib/action_dispatch/middleware/server_timing.rb, line 58
def call(env)
  response = nil
  events = @subscriber.collect_events do
    response = @app.call(env)
  end

  headers = response[1]

  header_info = events.group_by(&:name).map do |event_name, events_collection|
    "%s;dur=%.2f" % [event_name, events_collection.sum(&:duration)]
  end

  if headers[ActionDispatch::Constants::SERVER_TIMING].present?
    header_info.prepend(headers[ActionDispatch::Constants::SERVER_TIMING])
  end
  headers[ActionDispatch::Constants::SERVER_TIMING] = header_info.join(", ")

  response
end