Class: ActionDispatch::ServerTiming
- Inherits:
-
Object
- Object
- ActionDispatch::ServerTiming
- Defined in:
- lib/action_dispatch/middleware/server_timing.rb
Defined Under Namespace
Classes: Subscriber
Class Method Summary collapse
-
.unsubscribe ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ServerTiming
constructor
A new instance of ServerTiming.
Constructor Details
#initialize(app) ⇒ ServerTiming
Returns a new instance of ServerTiming.
52 53 54 55 56 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 52 def initialize(app) @app = app @subscriber = Subscriber.instance @subscriber.ensure_subscribed end |
Class Method Details
.unsubscribe ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 48 def self.unsubscribe # :nodoc: Subscriber.instance.unsubscribe end |
Instance Method Details
#call(env) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File '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 |