From ffcf2c691e51c6a70123bd0de389886d1e61ddda Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 5 Oct 2023 09:50:08 +0200 Subject: [PATCH] Fix Vary headers not being set on some redirects (#27272) --- app/controllers/concerns/web_app_controller_concern.rb | 10 ++++++---- app/controllers/follower_accounts_controller.rb | 1 - app/controllers/following_accounts_controller.rb | 1 - spec/requests/cache_spec.rb | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/concerns/web_app_controller_concern.rb b/app/controllers/concerns/web_app_controller_concern.rb index 273d7344c..5687d6e5b 100644 --- a/app/controllers/concerns/web_app_controller_concern.rb +++ b/app/controllers/concerns/web_app_controller_concern.rb @@ -4,10 +4,10 @@ module WebAppControllerConcern extend ActiveSupport::Concern included do - prepend_before_action :redirect_unauthenticated_to_permalinks! - before_action :set_app_body_class - vary_by 'Accept, Accept-Language, Cookie' + + before_action :redirect_unauthenticated_to_permalinks! + before_action :set_app_body_class end def skip_csrf_meta_tags? @@ -22,7 +22,9 @@ module WebAppControllerConcern return if user_signed_in? && current_account.moved_to_account_id.nil? redirect_path = PermalinkRedirector.new(request.path).redirect_path + return if redirect_path.blank? - redirect_to(redirect_path) if redirect_path.present? + expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in? + redirect_to(redirect_path) end end diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index ffdbd0180..5effd9495 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -3,7 +3,6 @@ class FollowerAccountsController < ApplicationController include AccountControllerConcern include SignatureVerification - include WebAppControllerConcern vary_by -> { public_fetch_mode? ? 'Accept, Accept-Language, Cookie' : 'Accept, Accept-Language, Cookie, Signature' } diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index cce296f9f..268fad96d 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -3,7 +3,6 @@ class FollowingAccountsController < ApplicationController include AccountControllerConcern include SignatureVerification - include WebAppControllerConcern vary_by -> { public_fetch_mode? ? 'Accept, Accept-Language, Cookie' : 'Accept, Accept-Language, Cookie, Signature' } diff --git a/spec/requests/cache_spec.rb b/spec/requests/cache_spec.rb index 178d19ed0..c391c8b3d 100644 --- a/spec/requests/cache_spec.rb +++ b/spec/requests/cache_spec.rb @@ -30,6 +30,7 @@ module TestEndpoints /directory /@alice /@alice/110224538612341312 + /deck/home ).freeze # Endpoints that should be cachable when accessed anonymously but have a Vary