Class: Debugbar::TrackCurrentRequest
- Inherits:
-
Object
- Object
- Debugbar::TrackCurrentRequest
- Defined in:
- lib/debugbar/middlewares/track_current_request.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ TrackCurrentRequest
constructor
A new instance of TrackCurrentRequest.
Constructor Details
#initialize(app) ⇒ TrackCurrentRequest
Returns a new instance of TrackCurrentRequest.
3 4 5 |
# File 'lib/debugbar/middlewares/track_current_request.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/debugbar/middlewares/track_current_request.rb', line 7 def call(env) # we don't check if debugbar is enabled because this middleware is only added when it is # Set `ignore` attribute to reuse it anywhere ::Current.ignore = .config.ignore_request?(env) return @app.call(env) if ::Current.ignore? req_id = SecureRandom.uuid ::Current.new_request!(req_id) status, headers, body = @app.call(env) # TODO: Remove this if statement? # We check meta because the frontend doesn't support request without meta yet. # It might happen with ActionController::Live where the following code # will run BEFORE ActionControllerEventSubscriber.process_action is called if ::Current.request&. RequestBuffer.push(::Current.pop_request!) # TODO: Refactor since not having ActionCable might be more common than I thought if defined?(ActionCable) ActionCable.server.broadcast("debugbar_channel", RequestBuffer.to_h) end end # We can't use Rails.application.url_helper here because 1. we have to set up manually the hosts, 2. the route I # want is inside the engine routes and I didn't manage to access them via the helper headers["X-Debugbar-Url"] = "#{ActionDispatch::Request.new(env).base_url}#{Debugbar.config.prefix}/get/#{req_id}" [status, headers, body] end |