DEV: early hints around_action -> after_action (#26423)

Using around_action means `add_early_hint_header` is in the stack for every request, and gets included in the backtrace of any errors.

We can manage with an after_action instead, which avoids adding to the stack depth (and avoids people blaming me for unrelated application errors 😉)
This commit is contained in:
David Taylor
2024-04-04 14:37:44 +01:00
committed by GitHub
parent 2995da2625
commit 39ae85b0e7
3 changed files with 12 additions and 27 deletions

View File

@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
after_action :add_noindex_header_to_non_canonical, if: :spa_boot_request?
after_action :set_cross_origin_opener_policy_header, if: :spa_boot_request?
after_action :clean_xml, if: :is_feed_response?
around_action :add_early_hint_header, if: -> { spa_boot_request? }
after_action :add_early_hint_header, if: -> { spa_boot_request? }
HONEYPOT_KEY ||= "HONEYPOT_KEY"
CHALLENGE_KEY ||= "CHALLENGE_KEY"
@ -1100,11 +1100,7 @@ class ApplicationController < ActionController::Base
# to cache a response header from the app and use that to send an Early Hint response to future clients.
# See 'early_hint_header_mode' and 'early_hint_header_name' Global Setting descriptions for more info.
def add_early_hint_header
return yield if GlobalSetting.early_hint_header_mode.nil?
@asset_preload_links = []
yield
return if GlobalSetting.early_hint_header_mode.nil?
links = []